如何在View Helper中将Action Helper作为代理方法调用?

时间:2011-10-01 21:43:03

标签: zend-framework view-helpers

我有Action Helper,它是数据库抽象层。

我想在View Helper中访问它,以便从模型中读取和显示一些数据。

在Controller中我将Action Helper称为代理方法,但如何在View Helper中实现相同的功能?

控制器中的某处:

$this->_helper->Service("Custom\\PageService");

Service.php:

...
public function direct($serviceClass)
{
    return new $serviceClass($this->em);
}

1 个答案:

答案 0 :(得分:3)

更好的方法是在其中创建一个视图助手

  Zend_Controller_Action_HelperBroker::getStaticHelper('service')->direct("Custom\\PageService");

另一种方式是在控制器init方法内部执行

$this->view->helper = $this->_helper;

所以在视图(phtml)中你可以做到

$this->helper->Service("Custom\\PageService");