Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you use <code>$this</code> from within a .phtml file you are refering to an instance of <a href="http://framework.zend.com/manual/en/zend.view.introduction.html" rel="nofollow">Zend_View</a>. This object is setup for you by your controller object which is an instance of <a href="http://framework.zend.com/manual/en/zend.controller.action.html" rel="nofollow">Zend_Controller_Action</a>.</p> <p><a href="http://framework.zend.com/manual/en/zend.controller.action.html" rel="nofollow">Zend_Controller_action</a> ensures that your view object has access to any view helpers that it needs. So, yes, you do have access to any helpers in the library/Zend/View/Helpers directory through the <code>$this</code> variable.</p> <p>You also have access to any helpers that you write yourself and place in the application/views/helpers directory through <code>$this</code>. See the manual about <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.custom" rel="nofollow">writing your own view helpers</a>. Once you start, you'll use them all the time as this is a very simple and powerful method of keeping your <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">code DRY</a>.</p> <p>Incidentally, you also have direct access in the same way to any <a href="http://framework.zend.com/manual/en/zend.filter.html" rel="nofollow">filters</a> you place in the application/views/filters directory as you can see from the docblock for initView() in Zend/Controller/Action.php.</p> <pre><code>/** * Initialize View object * * Initializes $view if not otherwise a Zend_View_Interface. * * If $view is not otherwise set, instantiates a new Zend_View * object, using the 'views' subdirectory at the same level as the * controller directory for the current module as the base directory. * It uses this to set the following: * - script path = views/scripts/ * - helper path = views/helpers/ * - filter path = views/filters/ * * @return Zend_View_Interface * @throws Zend_Controller_Exception if base view directory does not exist */ public function initView() </code></pre> <p>The whole process from request to response in Zend Framework is quite complicated. There are some diagrams available <a href="http://www.kitpages.fr/data/bundle/kitpagesfile/18/18/sequence_globale.jpg" rel="nofollow">here</a> and <a href="http://www.slideshare.net/polleywong/zend-framework-dispatch-workflow" rel="nofollow">here</a> if you are interested.</p> <p>Zend Framework is very powerful and is easy to use once you have overcome the learning curve which is quite steep. It is worth persevering though as you eventually 'get it' and produce better code faster as a result. I struggled with the <a href="http://framework.zend.com/manual/en/manual.html" rel="nofollow">documentation</a> and the <a href="http://framework.zend.com/apidoc/1.11/" rel="nofollow">API</a>, but found that the best documentation is the code. I now have the code for any component of ZF that I am using open in a seperate netbeans window for ease of reference.</p> <p>Good luck wth ZF.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload