Jump to content

"$this" outside classes? Someone explain...


BZero

Recommended Posts

I'm just starting to learn OOP and frameworks, and I read this (http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf) Zend framework tutorial, and it uses "$this" all over the place. Isn't "$this" supposed to be used inside classes to refer to the class it's in? If you, for example, go to the bottom of page 12 in that tutorial, "$this" is used right at the beginning of a new file. Is that entire .phtml file somehow inside a class? I'm confused...

Link to post
Share on other sites

Simplest way to check what $this is, is to var_dump($this);

AFAIR in this case it's an instance of Zend_View, and a view script are executed in its context.

Link to post
Share on other sites
    /**
     * Includes the view script in a scope with only public $this variables.
     *
     * @param string The view script to execute.
     */
    protected function _run()
    {
        if ($this->_useViewStream && $this->useStreamWrapper()) {
            include 'zend.view://' . func_get_arg(0);
        } else {
            include func_get_arg(0);
        }
    }

Link to post
Share on other sites

OK, so if I make a new .phtml file in views/scripts/{controller name}/ and use "$this" in that file, that would automatically refer to the Zend_View class, without me having to do anything else to make it that way?

Link to post
Share on other sites

But that's done automatically by ViewRenderer, right?

 

From the tutorial: "Zend Framework provides an Action Helper for us called the ViewRenderer. This takes care of initialising a

view property in the controller($this->view) for us[...]"

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.