What's the correct way to add Observers to a derived class where its parent class already has some observers?
In the example below, I would like the Model_Derived class to add a new Observer for 'before_create' but still maintain the Observers defined in the Model_Base class.
Any suggestions other than copying and pasting the Observers from the base class into the derived class?
It's functionality provided by the Fuel Autoloader.
You can see it as the static equivalence of the constructor, it is called as soon as the autoloader loads the class. It is available for every class defined within the framework.
Something weird happens when I add an Observer via _init().
It works but the Observer is also called by related objects.
I have a class called User which has a many-to-many relationship with Projects. I attach the Observer SendMail to the 'on_save' event for the User class using _init().
If I add a Project to a User object, the SendMail Observer is called not only when the User is saved (as expected) but also for every Project object associated with that User. This doesn't happen if I add the Observer to the User class via the traditional static _observers member.
Any idea what's going on here? I tried tracing it and SendMail is in the array returned by Project::observers()
I ask about a bug because we're still on v1.0. Doing a full update isn't an option at this point but I could selectively grab some code that fixes this. I did a search and I couldn't find any evidence of a known bug related to Observers and relations.
Then it probably is. Unfortunately, we don't have the time to support almost 3 year old code.
You'll have to dive into the ORM's model.php, and debug the observers() method (which loads and parses the observer definition) and the observe() method that calls them.
I'm pretty sure the structure of the observers array was different in 1.0 then it is today, so current docs are not relevant at that point.