Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorguillaumev
     
    Hi,

    I'm new to Akelos but very familiar with Rails.

    There is something, however, I wasn't able to find out using Akelos: how can I attach an observer to a model, and not only to a model instance. Let's say I have a model Comment and an observer CommentObserver. How can I tell the application that, every time a Comment is saved (any comment, not just a specific instance), the observer has to be triggered. I read the doc and it showed me how to attach an observer instance to a specific model instance, but I can't figure out how to attach it to every Comment that gets created.

    Thank you for your help.

    Guillaume.
    •  
      CommentAuthorbermi
     

    Hi and welcome to Akelos.

    In order to observe all instances of a Person model you can use create app/models/person_observer.php with the code

    class PersonObserver extends AkObserver
    {
        // Use predefined callbacks
        public function afterCreate(&$Person) { }
        public function afterSave(&$Person){ }
        public function afterValidationOnCreate(&$Person){ }
        public function afterValidationOnUpdate(&$Person){ }
        public function beforeSave(&$Person){ }
        public function beforeCreate(&$Person){  }
        public function beforeValidationOnCreate(&$Person){ }
        public function beforeValidation(&$Person){ }
        public function afterValidation(&$Person) { }
    }
    

    You can also use the common observer pattern methods update/notify.

    I hope that helped.