鸟哥,还是关于forward的问题,在启注册了Yaf_Plugin_Abstract实例后可以hook到preDispatch,postDispatch。发现如果Controller中发生了forward,preDispatch中可以正确的hook到$request和$response,但是postDispatch中的$request变成了forward后的对象,道理上讲的同,不过有几个不方便的地方:
1.preDispatch和postDispatch受forward影响,两个传入参数不一致,还得手工分析
2.forward(Controller,Action)这种模式不能在init中进行
3.forward发生的action不能区分是否skip rander了,即缺少在action中skip rander机制.
测试代码如下
Bootstrap.php中的
public function _initLayout(Yaf_Dispatcher $dispatcher){
$layout = new LayoutPlugin(‘layout.phtml’);
Yaf_Registry::set(‘layout’, $layout);
$dispatcher->registerPlugin($layout);
}
其中,LayoutPlugin采用手册中的默认代码(只有hook方法)
index.php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$this->forward(‘Login’,’login’);
}
}
login.php
class LoginController extends Yaf_Controller_Abstract {
public function loginAction() {
echo __METHOD__,”;
}
}