View Helper Case Notes
This is how it works:
views/helpers/MyHelper.php contains class Zend_View_Helper_MyHelper which has a function called myHelper()
Also, if you add a function called setView() to your class, then the View will pass you an instance of itself before it calls your view helper function.
i.e.
Class Zend_View_Helper_MyHelper
{
protected $_view;
public function setView($view)
{
$this->_view = $view;
}
public function myHelper($myVar)
{
return $this->_view->escape($myVar);
}
}
Hi Rob,
I have a small question about this convention: Why we have to prefix the helper classes with "Zend_View_Helper_"? it is, from my point of view, unnessacery. Moreover if you want use this convention let's create a base class Zend_View_Helper_BaseHelper which includes setView($view) and everyone else will inherit from that class.
Hope it is not too late,
Thank you for your time,
Roy
Roy,
The reason that Zend_View_Helper is there is so that the default view helpers map to the directory where the view helper is stored.
You can set the prefix to whatever you like when you set up the helper path for your own helpers:
$view->setHelperPath('/path/to/more/helpers', 'My_View_Helper');
Regards,
Rob…
Rob:
I really want to know when it's necessary to use a helper and how can I use it.
Thanks,
Felipe
Hi Rob,
Do you have experience with Zend_View's filter? I seek high and low but couldn't get any useful info on this topic.
Thanks,
Loke
Hi Johnny,
TBH, I haven't really used them as I haven't found a need for filters in any of our apps so far.
Regards,
Rob…