class My_View_Helper_Gender extends Zend_View_Helper_Abstract
{
public function Gender()
{
//
}
}
"The class method (Gender()) must be named identically to the concliding part
of your class name(Gender).Likewise,the helper's file name must be named
identically to the method,and include the .php extension(Gender.php)"
(Easyphp websites J.Gilmore)
My question is: Can A view Helper contain more than one method?And can I call other view helpers from within my helper?
thanks
Luca
Yes, helpers can contain additional methods. To call them, you have to get hold of the helper instance. This can be achieved either by getting a helper instance in the View
$genderHelper = $this->getHelper('Gender');
echo $genderHelper->otherMethod();
or by having the helper return itself from the main helper method:
class My_View_Helper_Gender extends Zend_View_Helper_Abstract
{
public function Gender()
{
return $this;
}
// … more code
}
and then call $this->gender()->otherMethod()
Because View Helpers contain a reference to the View Object, you can call any available View Helpers from within a View Helper as well, e.g.
public function Gender()
{
echo $this->view->translate('gender');
// … more code
}
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