Controller_Plugin 的奇怪行为
在此示例中,我希望每次进入控制器时将名为“test”的会话变量增加一。如果注释方法 preDispath 的内容工作正常,但对于这个精确的示例,会话变量“test”每次都会增加 3 或 5。 我使用 Zend Framework 1.11.4
为什么???我希望你能理解我的问题。
请记住,这个示例只是为了显示 preDispatch 方法的奇怪行为
我的插件
class App_Plugins_Permisos extends Zend_Controller_Plugin_Abstract{
public function __construct(){}
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$request->setModuleName('default');
$request->setControllerName('index');
$request->setActionName('index');
}
}
我的引导程序
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
protected function _initSession(){
Zend_Session::start();
}
protected function _initPlugins(){
$this->bootstrap('frontcontroller');
$this->frontController->registerPlugin(new App_Plugins_Permisos());
}
}
我的控制器
class IndexController extends Zend_Controller_Action{
public function init(){}
public function indexAction(){
$s = new Zend_Session_Namespace('test');
if(isset($s->test)){
$s->test++;
}else{
$s->test = 1;
}
Zend_Debug::Dump($s->test);
die();
}
}
非常感谢
In this example I want increase the session variable called "test" by one each time it enter to the controller. If comment the content of the method preDispath works fine but with this precise example, the session variable "test" increase in 3 or 5 each time.
I use Zend Framework 1.11.4
Why??? I hope you understand my question.
Remember this example is only to show the strange behavior of the method preDispatch
My plugin
class App_Plugins_Permisos extends Zend_Controller_Plugin_Abstract{
public function __construct(){}
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$request->setModuleName('default');
$request->setControllerName('index');
$request->setActionName('index');
}
}
My bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
protected function _initSession(){
Zend_Session::start();
}
protected function _initPlugins(){
$this->bootstrap('frontcontroller');
$this->frontController->registerPlugin(new App_Plugins_Permisos());
}
}
My Controller
class IndexController extends Zend_Controller_Action{
public function init(){}
public function indexAction(){
$s = new Zend_Session_Namespace('test');
if(isset($s->test)){
$s->test++;
}else{
$s->test = 1;
}
Zend_Debug::Dump($s->test);
die();
}
}
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试放入 .ini resources.frontController.plugins.foo = "My_Plugin_Foo"
如果有效请告诉我!特恩克斯
Try it putting in .ini resources.frontController.plugins.foo = "My_Plugin_Foo"
If works tell me! Tnks