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?
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;
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With