1

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

我想在 View Helper 中访问它以读取和呈现模型中的一些数据。

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

控制器中的某处:

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

服务.php:

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

1 回答 1

3

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

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

另一种方法是在控制器 init 方法中做

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

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

$this->helper->Service("Custom\\PageService");
于 2011-10-02T10:42:04.813 回答