Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
1.1: Warning - Passing observers as array is dprecated
  • My model code:
    protected static $_observers = array(
            'Orm\Observer_CreatedAt' => array('before_insert'),
            'Orm\Observer_UpdatedAt' => array('before_save'),
            'Orm\\Observer_Validation' => array('before_save') 
        );
    

    I got the following warning on console:
    Warning - 2012-02-27 14:25:36 --> Orm\Model::observers - Passing observer events as array is deprecated, they must be
            inside another array under a key "events". Check the docs for more info.
    

    But the docs are not updated yet I think:
    http://docs.fuelphp.com/packages/orm/observers/intro.html#add_observers What is the proper way to do this in 1.1? Cheers & Thanks in advance!
  • As the warning says: the events need to be in a key named "events".
    // instead of 
    protected static $_observers = array(
            'Orm\Observer_CreatedAt' => array('before_insert'),
            'Orm\Observer_UpdatedAt' => array('before_save'),
            'Orm\\Observer_Validation' => array('before_save') 
        );
    
    // it should now be
    protected static $_observers = array(
            'Orm\\Observer_CreatedAt' => array('events' => array('before_insert')),
            'Orm\\Observer_UpdatedAt' => array('events' => array('before_save')),
            'Orm\\Observer_Validation' => array('events' => array('before_save')) 
        );
    

    Also as a sidenote: always add backslashes double, even if not necessary. Because if you don't do this always you will end up making mistakes or causing bugs you really don't understand as you only change one character and suddenly it stops working.
  • Thanks Jelmer! I was a little bit confused where to exactly put the array. And thanks for pointing out the backslash issue! You guys do a really awesome job providing support here (for free).

Howdy, Stranger!

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

In this Discussion