2011-10-01 39 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

毫無疑問,第一個將是更好的解決方案。 –

相關問題