2011-12-14 128 views
1
class AboutController extends Zend_Controller_Action 
{ 

    public function init() 
    { 
     /* Initialize action controller here */ 
    } 

    public function indexAction() 
    { 
     $this->getResponse() 
      ->appendBody(' hello from aboutAction'); 

     $this->_forward('nothing','index', null, array('email' => '[email protected]')); 
    } 

    public function contactAction() 
    { 
     $this->view->pageTitle="boolbool"; 
    } 


} 

該指數操作調用任何控制器的指數函數:Zend框架控制器停止工作

class NothingController extends Zend_Controller_Action 

{ 


public function init() 

{ 

    /* Initialize action controller here */ 

    } 



public function indexAction() 

    { 

    $email=$this->_getParam('email','not found'); 
    $this->getResponse->appendBody('The email is: '.$email); 
} 




} 

但空話指數動作永遠不會triggered..I獲得關於頁面instead..why頁面未找到?

我不能甚至訪問我沒什麼控制器,即使它在大約沿着文件存在(我可以觸發有關的動作,雖然)

回答

3

我覺得你的$this->_forward() PARAMS是南轅北轍:

從Zend Framework的Zend_Controller_Action類:

/** 
    * Forward to another controller/action. 
    * 
    * It is important to supply the unformatted names, i.e. "article" 
    * rather than "ArticleController". The dispatcher will do the 
    * appropriate formatting when the request is received. 
    * 
    * If only an action name is provided, forwards to that action in this 
    * controller. 
    * 
    * If an action and controller are specified, forwards to that action and 
    * controller in this module. 
    * 
    * Specifying an action, controller, and module is the most specific way to 
    * forward. 
    * 
    * A fourth argument, $params, will be used to set the request parameters. 
    * If either the controller or module are unnecessary for forwarding, 
    * simply pass null values for them before specifying the parameters. 
    * 
    * @param string $action 
    * @param string $controller 
    * @param string $module 
    * @param array $params 
    * @return void 
    */ 
    final protected function _forward($action, $controller = null, $module = null, array $params = null) 
    { 

所以對你來說應該是:

this->_forward('index', 'nothing', null, array('email' => '[email protected]')) 
+0

問題在這裏..在控制器索引內的兩個函數:$ email = $ this - > _ getParam('email','not found'); $ this-> getResponse-> appendBody('電子郵件是:'。$ email); – 2011-12-14 16:21:56