1

Is there anyway to add two of the same type of observer to a Model in FuelPHP (ORM). (I'd actually be using a custom observer rather than the CreatedAt at shown below)

protected static $_observers = array(
    'Orm\\Observer_CreatedAt' => array(
    ...
    ),
    'Orm\\Observer_CreatedAt' => array(
    ...
    ),
);

Obviously the above won't work because only one of a given key can be set in an array. Is there any workaround to avoid duplicating the observer file itself?

chicks
  • 2,393
  • 3
  • 24
  • 40
paullb
  • 4,293
  • 6
  • 37
  • 65

1 Answers1

2

No, the current ORM code does not allow you to add multiple observers of the same class.

Emlyn
  • 852
  • 6
  • 16
  • No hacky workaround short of duplicating the class file and giving it a slightly different name? – paullb Aug 23 '15 at 04:10
  • 1
    You could create a second observer like `class MyFakeObserver extends MyTargetObserver` and then use both observers in the model, it's not very clean at all but would allow you to use the same observer twice. – Emlyn Aug 23 '15 at 08:10
  • The other thing that comes to mind is updating your custom observer to be able to handle multiple properties at once, removing the need to add it to the model a second time. – Emlyn Aug 23 '15 at 08:10
  • The extending is certainly cleaner than coping the file outright. Editing the observer it handle mutliple would also be good. It would be good if the framework would allow this (like CakePHP does IIRC). Thanks for the help! – paullb Aug 23 '15 at 21:38
  • 1
    The issue will be addressed in the upcoming v2 as the way that observers are dealt with internally is going to change. Unfortunately we can't change it in v1 as it would create a huge backwards compatibility issue, as much as I would like to be able to make the v1 orm more sensible. – Emlyn Aug 24 '15 at 07:26