Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Event class example
  • Can anyone post an example on how work with the Event Class to "interact with the Fuel Core without having to alter any core files"?
    I'm trying to catch the moment inmediately before Request->send() occurs. Thanks in advance.
  • At the comment the core doesn't contain any event calls that you could use as a 'hook'. It is somethere we're considering for 2.0, but a lot of hook calls in the core will slow the core down, while not a lot of people will have a need for those hooks. Having said that, send() is a method on the Response object, not on the Request. And it does nothing more that echo'ing the stored response. So if you can explain what exactly you want to achieve, I might give you some pointers on how to do that.
  • Thanks Harro, you're right, I mean the Response Class. I've extended the Lang Class so calling the get function, anytime a language key is not found in the language file, is automatically added to the ::lines collection. What I intend is a method to save all the keys at once while I'm in development, so I can easely create a dictionary and pass it to the CMs (I mean the guys who manage the site content). Doing this in the after function in the controller doesn't work, as __() lang shortcut is processed after that. So I was looking for some hook I can use to trigger the Lang::save function. I've assumed triggering this right before the content is served was a good idea. I intend to use this while developing only, so performance is not an issue. Thanks again.
  • The request is called from your index.php, so perhaps that's the place to do it. Otherwise, you can use the Event class to register a shutdown function:
    \Event::register('shutdown', 'Myclass::mymethod');
    
    which will call that method in the request shutdown process, after the output has been generated and sent to the browser. ( shutdown is actually the only event that IS defined in the FuelPHP core )
  • Thanks Harro, I'll try that. By the way, you are WanWizard, right?
  • That'll be me, yes.
  • how to use Event::shutdown(); in version 1.7.3
  • To run something on shutdown?

    Event::register('shutdown', 'Class::method');

Howdy, Stranger!

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

In this Discussion