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
Custom Observer throwing error, not found
bperin
November 2013
**edit added correct code
I'm trying to add a custom observer to a model the observer is located in
/classes/observer/gcm.php
class Observer_Gcm extends Orm\Observer
{
public function after_insert(Orm\Model $model){
\Log::debug('after insert observer');
}
}
and then in my Model
protected static $_observers = array(
'Orm\Observer_CreatedAt',
'Orm\Observer_UpdatedAt',
'Observer_Gcm'=>array(
'events'=>array('after_insert')
)
);
But it throws the error that the class doens't exist found in /packages/orm/classes/model.php 1511
$observer_class = \Inflector::get_namespace($observer).'Observer_'.\Inflector::denamespace($observer);
if ( ! class_exists($observer_class))
{
throw new \UnexpectedValueException($observer);
}
bperin
November 2013
Ok i sorta got it to work but I had to manually edit the Orm bootstrap file to add the class
'Orm\\Observer_Gcm' => __DIR__.'/classes/observer/gcm.php',
and put the actual observer with the others in the Orm package... this seems like a terrible way to do this
Harro
November 2013
Accepted Answer
Your custom observer should not be in the Orm namespace, since that namespace is reserved for the Orm package (which is a core package and should not be altered).
Any other namespace will do, this works fine:
protected static $_observers = array(
'Orm\Observer_CreatedAt',
'Orm\Observer_UpdatedAt',
'My\Own\Observer_Gcm'=>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,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
bperin
November 2013
Harro
November 2013