For a Magento shop I’m working on I have to check certain session variables on each load of a page. When the variables don’t have the expected values I need to redirect to certain page.
No I wonder how I could implement such a behavior. Normally I would do the check in action methods of each controller, but I don’t want to rewrite each controller or all their base classes.
Is there a easier way?
Magento’s event architecture to the rescue! Observe the
controller_action_predispatchmethod.Edit: Note that this event is dispatched in both adminhtml and frontend, so Sergy’s answer is important – configure the event observer under the appropriate area.