2011-04-08 22 views
1

在正常操作中,我會這樣做$this->_forward()。我想在動作助手中做同樣的事情。這不起作用如何在行動助手中撥打電話

$this->getActionController()->_forward(''); 
$this->_actionController()->_forward(''); 
+1

你試過$ this - > _ forward()嗎? – markus 2011-04-08 16:58:30

+0

對_forward($ action,$ controller)的調用會更改請求對象,並再次在調度週期中運行。你能提供一些關於你爲什麼要在動作助手中使用前進的想法嗎? – Ifthikhan 2011-04-08 21:12:31

回答

1

_forward是受保護的功能,所以顯然無法通過

$this->getActionController()->_forward(''); 

最簡單的方法把它做forward方法在公共範圍內使用的是使新forward()方法(注意「前進」不「_forward)和代理它的_forward方法:

class App_Controller_Action extends Zend_Controller_Action 
{ 
    public function forward($action, $controller = null, $module = null, array $params = null) 
    { 
     return $this->_forward($action, $controller, $module, $params); 
    } 
} 

沒有測試它,但它應該工作 快樂黑客。

+0

應該能夠直接覆蓋'_forward()',因爲從受保護移動到公共_expands_的可見性。 – 2011-04-09 02:57:41

+0

_forward是一個最終的保護功能,所以除非你想改變你的本地框架副本的源代碼,否則你不能那麼做 – Fatmuemoo 2011-04-11 18:07:38

+0

D'oh!絕對正確,我沒有意識到'_forward()'被列爲'final'。感謝您的高舉。 – 2011-04-12 05:21:39