Render Error In A Controller If Variable Is False

In my Store controller I have an init() function that find out what currency the current store is. I then need to find out if the currency is the same currency of the users cart. If they do not match I need to stop the store from loading the action it was trying to do initially and render an error view.

What is the best method to do this? A redirect from init is not ideal since it will make an infinite loop, since init() runs all the time. Is this something that actions can handle?

Isn’t this method only called by the application before the controller starts to execute?

If so you can redirect to error action in different controller.

Thanks for the reply Bizley!

The error is specific to this controller. My main errorHandler goes through site/error. So I cannot use that.

What I ended up doing is moving the check out of the init() and put it in my actions. I only have 2 actions in this controller so it’s manageable for now.

Glad to hear that :) There is always a solution.