您正在尝试在我的应用程序中添加自定义帮助程序
已完成以下步骤
index.php
$view = new Zend_View();
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
My / View / Helper中的助手类
class My_View_Helper_Common extends Zend_View_Helper_Abstract
{
public function example()
{
return "ok";
}
}
现在调用视图index.phtml
$this->example()
我收到此错误
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):
请帮帮我
答案 0 :(得分:5)
除了Vikas的回答。
要在视图助手中调用多个方法,您可以使用以下代码:
在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();
}
}
在你的观点中:
echo $this->example()->foo() // prints foo
echo $this->example()->bar() // prints bar
echo $this->example() // prints foo
答案 1 :(得分:1)
好像你有两个问题:
因此,在您的情况下,文件My/View/Helper/Example.php
包含以下正文
class My_View_Helper_Example extends Zend_View_Helper_Abstract {
public function example() {...}
}
然后您就可以使用
从视图中调用它$this->example()