Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Where do observers go?
bharold
January 2013
I have created a custom observer and placed the file in:
fuel/app/classes/observers/structure.php
It looks like this:
<?php
namespace Orm;
class Observer_Structure extends Observer
{
public function after_insert()
{
\Log::info('Successfully called observer');
}
}
and I have modified one of my models with the following $_observers:
protected static $_observers = array(
'Orm\Observer_Structure' => array(
'events' => array('after_insert'),
),
);
When the model tries to trigger the observer, I get this error:
UnexpectedValueException [ Error ]: Orm\Observer_Structure
PKGPATH/orm/classes/model.php @ line 1356
I have also tried:
protected static $_observers = array(
'Orm\Observer\Structure' => array(
'events' => array('after_insert'),
),
);
I then get this error:
UnexpectedValueException [ Error ]: Orm\Observer\Structure
PKGPATH/orm/classes/model.php @ line 1356
and also:
protected static $_observers = array(
'Orm\Observer\Observer_Structure' => array(
'events' => array('after_insert'),
),
);
that gives me this error:
UnexpectedValueException [ Error ]: Orm\Observer\Observer_Structure
PKGPATH/orm/classes/model.php @ line 1356
I have also tried locating the observer file at:
fuel/app/classes/orm/observers/structure.php
but I get the same three errors as above.
My questions are:
- Where do I put observers for my application?
- What do I name the observer file?
- How do I call the observer?
bharold
January 2013
Accepted Answer
Custom observers belong in:
/fuel/app/classes/orm/observer
The file should be named after the observer. For example, if the observer is Observer_Structure, the file name should be structure.php
The correct syntax for the $_observers in the model for this example is:
'Orm\Observer_Structure' => array(
'events' => array('after_insert'),
),
bharold
March 2013
If somebody else wants to comment on this thread I will mark it as answered. Apparently you cannot accept your own response as an answer.
Harro
March 2013
I can do that for you.
:-)
btw, there is no set location, you can put observers anywhere you want. I have mine for example in fuel/app/classes/model/observer, and I use
'Model\Observer\Structure' => array(
'events' => array('after_insert'),
),
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
bharold
March 2013
Harro
March 2013