2015-01-08 66 views
0

我有一个视图助手像的下方,它工作完美的罚款:Zend Framework1,有没有一种方法可以覆盖每个Controller的Zend_View_Helper_ *函数?

class Zend_View_Helper_List extends Zend_View_Helper_Abstract 
{ 
    public function list() 
    { 
     return '<ul><li>Something Really Good</li></ul>'; // generated html 
    } 
} 

我有这个在我的全球布局myapp.phtml

<div><?php echo $this->list(); ?></div> 

我的问题是如何在不同的控制器覆盖list()甚至更细粒度,每个控制器的行动?

我试图在每个控制器中设置一个View变量,例如$this->view->type,然后将它传递给列表函数<div><?php echo $this->list($this->type); ?></div>,但它看起来很脏并且不正确!

回答

1

您可以将帮手放在特定控制器的view/helpers文件夹中,以便它仅对此控制器可见。

如果您需要对每个操作进行更改,您还可以为帮手$this->view->setHelperPath('MyScripts/View/Helper/','MyScripts_View_Helper');添加新路径。

0

如果你只想要一个单一的视图助手,你可以有效地使用变量。
你可以尝试这样的事情:

在你的Foo操作:

$this->view->type = 'action_foo'; 

在您的视图助手:

public function list() 
{ 
    if (isset($this->view->type)){ 
     if ('action_foo' == $this->view->type) 
      return '<ul><li>Something Really Good for Foo Action</li></ul>'; // generated html 
     else 
      return '<ul><li>' . $this->view->type . '</li></ul>'; // generated html 
    } 
    else 
     return '<ul><li>Something Really Good</li></ul>'; // generated html 
} 
相关问题