Before-Action method in symfony2

≯℡__Kan透↙ 提交于 2019-12-11 04:04:31

问题


I want to write a common code in my symfony2 application that should be executed before calling any action-method. How Can I do it?

At the time of login-success, I am storing some data in session. If the user visit the application later with remember-me functionality. I want to restore the session data. The common code is to restore the session data.


回答1:


The method to setup before and after Filters are available in the documentation. Please see the link http://symfony.com/doc/2.0/cookbook/event_dispatcher/before_after_filters.html




回答2:


You can use JMSAopBundle, intercepting all action method for a given controller (or any controller).




回答3:


I think that https://github.com/symfony/symfony/issues/1975 can be helpful. Basically you have to create listener which will be listen at kernel.controller event and call some method from controller there.



来源:https://stackoverflow.com/questions/13429788/before-action-method-in-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!