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' => 'me@example' ) );
}
public function contactAction()
{
$this->view->pageTitle="boolbool";
}
}
此索引操作不会调用控制器的索引函数:
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 );
}
}
但是nothings索引动作永远不会被触发..我在about页面中找不到页面而不是..为什么?
我甚至无法访问我的无控制器,即使它与about一起存在于文件中(尽管我可以触发about操作)
答案 0 :(得分:3)
我认为你的$this->_forward()
参数是错误的:
来自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' => 'me@example' ))