How to call a specific method in each action method of all controller classes in Magento?

For the Magento store I am working on, I have to check certain session variables on every page load. When the variables don't have the expected values, I need to redirect to a specific page.

No, I'm wondering how I could implement this behavior. I would normally do in-action validation of each controller's methods, but I don't want to rewrite each controller or all of their base classes.

Is there an easier way?

+3


source to share


2 answers


Magento event architecture to the rescue! Follow the method controller_action_predispatch

.



Edit . Please note, this event is dispatched to both adminhtml and frontend, so Sergy's answer is important - set up an event watcher in the appropriate scope.

+6


source


Yes,
you can always use magento events in this case:
 1 controller_action_postdispatch

..
 2 controller_action_predispatch

..
Be careful, the same events are used in the administration area.



+5


source







All Articles