2011-10-01 38 views
1

我有Action Helper是数据库抽象层。如何在视图助手中作为代理方法调用Action Helper?

我想在View Helper中访问它来阅读和展示模型中的一些数据。

在控制器中我调用Action Helper作为代理方法,但是如何在View Helper中实现相同的功能?

某处控制器:

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

Service.php:

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

回答

3

更好的方式是创建一个视图助手里面做

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

另一种方式是内部控制器init方法做

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

所以在视图(PHTML),你可以做

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

问题保持这将是更好的解决方案。我认为第一个因为你不依赖'Controller'。你怎么看? – pixel

+2

毫无疑问,第一个将是更好的解决方案。 –

相关问题