Where can I put view scripts needed for view helpers (using Zend_View and the default directory layout)?

I have a relatively complicated part of my application that is an access control list editor. I need to reuse it in several places, and I would like it to be loaded by all ajax-y, etc.

Since I need to use it often, I would like to do it in Zend_View_Helper. It's simple - just put it $view->setHelperPath(APPLICATION_PATH . '/views/helpers', 'Cas_View_Helper');in the boot file for the view, and everything seems to be set up with respect to loading the view helper.

However, the helper really needs to be output using the script view. Is there a standard place where I have to put this?

+5
source share
4 answers

Usually, when an assistant needs a script view, this script is placed inside a partial one. The location of this partial file may vary depending on the structure of your directory, but the standard is:

application[/modules/name]/views/scripts/partials/

You can write an assistant with something like this:

class Cas_View_Helper_Foo extends Zend_View_Helper_Abstract 
{
    protected $partial = 'partials/foo.phtml';
    protected $view = null;

    // Render the partial here
    public function foo($params)
    {
        $this->view->partial($this->partial, $params);
    }

    // Specifying this method Zend_View will inject the view here
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }

}
+8
source

You can always add a “generic” view path using

$view->addScriptPath('/path/to/shared/view/scripts')

http://framework.zend.com/manual/en/zend.view.controllers.html#zend.view.controllers.script-paths .

Also, see how Zend_Paginator handles a partial rendering view.

+1
source

, -, , . ZF, , , , . .

- , , . : application[/modules/name]/views/scripts/helpers/{your helper}/blah.phtml, .

, , , . , :

application[/modules/name]/views/helpers/{your helper}.php
application[/modules/name]/views/helpers/{your helper}/{view scripts}.phtml

.

+1
source

In the browse folder, you create a folder helper. Here you place view helpers.

0
source

All Articles