Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
own observer still dont work
  • in model i have in classes/model
        protected static $_observers = array(
            'examplex', // will call Observer_Example class for all events
        );
    
    observer in classes/observer
    namespace Kancelarske;
    
    class Observer_Examplex extends \Orm\Observer
    {
    
        public function before_save(Model $model)
        {
        }
    
    }
    
    when i saving..
    Orm\InvalidObserver [ Error ]: examplex
    PKGPATH/orm/classes/model.php @ line 973
    973 throw new InvalidObserver($observer); Backtrace PKGPATH/orm/classes/model.php @ line 565
    APPPATH/modules/kancelarske/classes/controller/tovar.php @ line 139
    COREPATH/classes/request.php @ line 381
    DOCROOT/index.php @ line 42
    i dont know where is a problem
  • Are you on the latest from the Orm develop branch?
    Is the model in the same namespace?
    Have you tried adding the observer with a full classname: "Kancelarske\\Observer_Examplex"
  • Jelmer Schreuder wrote on Thursday 26th of May 2011:
    Are you on the latest from the Orm develop branch?
    ok i copied now last develop branch.. but now it have other problem
    Jelmer Schreuder wrote on Thursday 26th of May 2011:
    Is the model in the same namespace?
    yes it is
    Jelmer Schreuder wrote on Thursday 26th of May 2011:
    Have you tried adding the observer with a full classname: "Kancelarske\\Observer_Examplex"
    when i set Kancelarske\\Observer_Examplex error is :
    ErrorException [ 4096 ]: Argument 1 passed to Kancelarske\Observer_Examplex::before_save() must be an instance of Kancelarske\Model, instance of Kancelarske\Model_Tovar given, called in /home/html/domain.com/fuel/packages/orm/classes/observer.php on line 23 and defined
    APPPATH/modules/kancelarske/classes/observer/examplex.php @ line 12 Backtrace COREPATH/base.php @ line 201
    APPPATH/modules/kancelarske/classes/observer/examplex.php @ line 12
    PKGPATH/orm/classes/observer.php @ line 23
    PKGPATH/orm/classes/model.php @ line 996
    PKGPATH/orm/classes/model.php @ line 757
    APPPATH/modules/kancelarske/classes/controller/tovar.php @ line 168
    COREPATH/classes/request.php @ line 381
    DOCROOT/index.php @ line 42

    when i set only examplex instead of Kancelarske\\examplex error is :

    UnexpectedValueException [ Error ]: examplex

  • Ahh, that's your fault. First take a look at the error you just posted and then at this method:
    public function before_save(Model $model)
        {
        }
    

    Your observer is in your own namespace so if you typehint Model from there it's expected to be an instance of Kancelarske\Model instead of Orm\Model. Thus the code should be:
    public function before_save(\Orm\Model $model)
        {
        }
    

    Really, errors often tell you exactly what you need to know. [edit:] To get the short form working try using "Examplex" instead of "examplex" - though the full classname is faster an more efficient (is checked first)
  • ehm :) public function before_save(Model $model) must be specificated model in parameter. thanks to KelsoB isnt possible set before_save for all models ? :P (not important)
  • Jelmer Schreuder wrote on Thursday 26th of May 2011:
    Ahh, that's your fault. First take a look at the error you just posted and then at this method:
    public function before_save(Model $model)
        {
        }
    

    Your observer is in your own namespace so if you typehint Model from there it's expected to be an instance of Kancelarske\Model instead of Orm\Model. Thus the code should be:
    public function before_save(\Orm\Model $model)
        {
        }
    

    Really, errors often tell you exactly what you need to know.
    thanks too ;)

Howdy, Stranger!

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

In this Discussion