Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Observer UnexpectedValueException
  • Hi there, I'm trying to create an observer that "logs" the logged user id in create_by and updated_by columns. More or less the same this as created_at and updated_at does. Here's what I have: 1) Created a new file under app/classes/observer/updatedby.php 2) Added this code to the file: http://scrp.at/aNL 3) In my Orm model added:
     protected static $_observers = array(
            'Orm\\Observer_CreatedBy' => array("before_insert"),
            'Orm\\Observer_UpdatedBy' => array("before_save"),
        );
    

    but when I tried to insert the new orm object I get the error:
    UnexpectedValueException [ Error ]: Orm\Observer_UpdatedBy
    

    I tried to debug it and I notice that in packages/orm/classes/model.php in observe method the var $observer_class has the value Orm\Observer_Observer_UpdatedBy that is wrong I think. Is this a bug or I am doing something wrong? Cheers
  • I think I see your problem. change:
    'Orm\\Observer_UpdatedBy' => array("before_save")
    

    to:
    'Observer_UpdatedBy' => array("before_save")
    

    Try it and let us know. :)
  • Hey jonhny Thanks, but still won't work, check this: http://i.imgur.com/erPZd.png maybe it helps :/
  • You should not prefix with 'Observer_', the ORM class does that for you, that's why you get it twice.
  • After some struggling and with the help of WanWizard in IRC I was able to get it work. My model: http://scrp.at/aNS My Observer: http://scrp.at/aNU located in app/classes/observer/updatedby.php Thank you all!
  • That's weird.. why would you 'edit' the ORM package by adding a new file? Why not create a new package (collection maybe) and extend from there and add the new package to the allways_load config?
  • Indeed, your solution is better.
  • You have to add your obsrver file to orm package bootstrap, it should fix the problem :)

Howdy, Stranger!

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

In this Discussion