Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Module Enable/Disable Auto Codes
  • Dear,

    I would like to use modules for my project, It is good,

    But I would like to do some Enable Observer Codes . ir. When module is enabled, Some codes will run,  Also when Module is disabled, Some codes will run, Each module need these enable/disable Observer codes, Anyway Possible?
  • HarroHarro
    Accepted Answer
    It's probably best to use the Event class for that, it allows you to add "observer" functionality anywhere you want.

    Define the events, and the code to run, and trigger the event when a module is enabled, passing details like module name for example.
  • a simple example please.

    i checked docs, but i cant see any event for module_enabled or Module_disabled....

    Kindly provide me info.
  • HarroHarro
    Accepted Answer
    No, you define your events yourself. The only predefined events are the ones that the framework itself triggers.

    For events that need to be available system wide, most people create an events class, and have that "always_load". In the class you can define your event methods, and use the _init() static method to register your events, like so:

    class Events
    {
        public static function _init()
        {
            \Event::register('some_event', 'Events::some_event');
        }

        public static function some_event()
        {
            \Log::info('Hurray, the event was triggered!');
        }
    }

    Then in your code, where you enable the module, you use

    \Event::trigger('some_event');

    to call the event method you have defined.

    In your case, you need methods for 'enable module' and 'disable module', and you need to trigger the event in your controller that has the enable/disable functionality.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion