Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've got a relatively complicated portion of my application, which is an editor for access control lists. I need to reuse it in a few places, and I'd like it to be loadable all ajax-y and such.

Because I need to use it often, I'd like to make it into a Zend_View_Helper. That's simple -- just put $view->setHelperPath(APPLICATION_PATH . '/views/helpers', 'Cas_View_Helper'); in the bootstrap for the view, and all seems to be set with regards to loading the view helper.

However, the helper really should be output using a view script. Is there a standard location where I should put that?

like image 502
Billy ONeal Avatar asked Oct 08 '10 01:10

Billy ONeal


2 Answers

Usually, when a helper need a view script this script is placed inside a partial. The location of that partial may vary depending on your directory structure, but the standard is:

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

You can write a helper 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;
    }

}
like image 130
Keyne Viana Avatar answered Nov 14 '22 23:11

Keyne Viana


You could always add a "shared" 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, have a look at how Zend_Paginator handles partial view rendering.

like image 33
Phil Avatar answered Nov 14 '22 21:11

Phil