Magento - Call method from custom module, on init

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply

I am new to magento. I've developed a new module that extends the customer module from magento. The thing is, that i need to call a method from this new module, on each request. The metod is "static public". So, no matter if the user is on the home page, product page or whatever, my method must be executed.

My question is where to integrate this method ? I don't want to alter the vendor's code !

If you have any ideas please ... and also please don't post stupid reply like "Why u need ?".

For example i can integrate it in index.php like this:

MyNewModule::executeMyNewMethod();

But i don't want to alter magento's code.

Thanks for quick reply Alan. So: I have

class MyModule_Customer_AccountController extends Mage_Customer_AccountController

This module is allready functional. Here i have a method:

public static function checkSomethingAtEveryRequest() { //... }

I want to enable

MyModule_Customer_AccountController::checkSomethingAtEveryRequest()

in every $_GET request in magento. Somehow to pre-execute this method globally in frontend.

I'd recommend using an observer to listen for an event.

Here's a list of the events that you can listen for:

http://www.magentocommerce.com/wiki/development/reference/event-list?do=diff

It depends on when exactly you want your code to execute, but I'd say you could listen to something like controller_front_init_before

Also, here's a blog post of mine that outlines using observers to listen to events. This one is specifically regarding cache, but the concept is the same:

http://mikebywaters.wordpress.com/2011/12/14/disable-magento-full-page-cache-on-a-per-controller-basis/

`Reply Or Comment!
Please LogIn to Reply!