Reputation:
Hi am trying to add custom helper throughout my application
Have done following steps
index.php
$view = new Zend_View();
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
Helper class in My/View/Helper
class My_View_Helper_Common extends Zend_View_Helper_Abstract
{
public function example()
{
return "ok";
}
}
now calling in view index.phtml
$this->example()
am getting this error
Uncaught exception 'Zend_View_Exception' with message 'script 'error/error.phtml' not found in path (.\application\views\scripts\)' in C:\xampp\htdocs\wyfixture\library\Zend\View\Abstract.php:924 Stack trace: #0 C:\xampp\htdocs\wyfixture\library\Zend\View\Abstract.php(827): Zend_View_Abstract->_script('error/error.pht...') #1 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(903): Zend_View_Abstract->render('error/error.pht...') #2 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(924): Zend_Controller_Action_Helper_ViewRenderer->renderScript('error/error.pht...', NULL) #3 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\Helper\ViewRenderer.php(963): Zend_Controller_Action_Helper_ViewRenderer->render() #4 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 C:\xampp\htdocs\wyfixture\library\Zend\Controller\Action.php(523):
please help me
Upvotes: 0
Views: 1811
Reputation: 4822
In addition to Vikas answer.
To call more than one method in a view helper you can use code like this:
In My/View/Helper/Example.php
class My_View_Helper_Example extends Zend_View_Helper_Abstract
{
public function example()
{
return $this;
}
public function foo()
{
return 'foo';
}
public function bar()
{
return 'bar';
}
public function __toString()
{
return $this->foo();
}
}
In you views:
echo $this->example()->foo() // prints foo
echo $this->example()->bar() // prints bar
echo $this->example() // prints foo
Upvotes: 5
Reputation: 3285
Seems like you have two problems here:
So, in your case it's file My/View/Helper/Example.php
with the following body
class My_View_Helper_Example extends Zend_View_Helper_Abstract {
public function example() {...}
}
Then you'll be able to call it from the view with
$this->example()
Upvotes: 1