I’ve a backend module which could only be accessed by authorized members. So I need to check authenticity for all actions and for all controllers. Currently I’m doing it inside preDispatch() functions inside controller classes. So it takes care of all the actions inside that controller. But still I’ve to do it for all controllers. Is there a place I could check it for all the controllers as well. So basically I want one place authenticity check for whole backend module. Can I do it in bootstrap?
Share
If you’re using a per-module bootstrap, you could certainly do it there. However, I would recommend keeping it at the controller level.
You can also continue to use the
preDispatch()method, but just move the logic into a controller plugin instead. This will affect thepreDispatch()call for every controller.Alternatively, you could just define the logic in a base controller that all other controllers inherit from. This is how I typically do it (because I choose when to call
_setLoginRequired()when I need it).