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

    Daily I am impressed with the coding in Akelos. Kudos to the developers and maintainers!

    Right now I'm looking into putting a 'afterSave' callback function on a model named 'part'. What I want to accomplish is each time a part is created or modified, another function called "qb_update_part($id)" is called (but only when the Ak save/update is successful). I see from the AkActiveRecord | Callbacks documentation that I can put

    function afterSave()  {  qb_update_part($this->id);  }
    

    Inside \app\models\part.php and the afterSave function will get called. My question is thus: How and where should I put my qb_update_part($id) function, and how can I call it? Currently I have it inside qb_controller.php. If it stays there, how do I call it from inside the part.php afterSave function mentioned above?

    Am I doing it wrong? Perhaps qb_update_part() should be in qb_helper.php? (Or are helpers only for the presentation output?) If so, how would I call it?

    Thanks for the help!

    • CommentAuthorkkrzyzak
     

    ... I'm not shure, but can't You put it into this model, and call by $this->qb_update_part(), or self::qb_update_part() (if it's static function, but I don't think so...)

    • CommentAuthorsuthern
     

    I could put the qb_update_part() function in this model, but it would have to rely on still other functions (like default qb database settings retrieval) that are currently in qb_controller.

    The other option would be to move the 'other relied-upon functions' into somewhere like \app\model\qb.php, then refer to them from the qb_update_part function inside this \model\part.php. Hmm. I know one can include any model they want to in any controller, but what about model to model? I guess experimentation wins again. ;-) I'll be back with an update when it works.

    • CommentAuthorsuthern
     

    Ok, it looks like I'm going to be putting all my shared QB functions into the shared_model.php, and any model specific functions inside each model/model_name.php file. I can also call any global (shared_model.php) functions through any controller. That'll be nice. Now, back to work self!

    • CommentAuthorKaste
     

    As I don't know what QB is. Just wanted to mention that you can observe models via ... AkObserver.

    If the after_save-routine doesnt belong to the model you can place it in an observer which observes the particular model.

    • CommentAuthorsuthern
     

    The 'Observer' part of AkActiveRecord does not include very many examples of how to use it. Can you point me towards some?

    QB is short of QuickBooks, the accounting package loathed by developers everywhere. ;-)

    • CommentAuthorKaste
     

    you have to decide if this would be a elegant solution to your problem.

    class MyObserver extends AkObserver
    {
        function afterSave(&$record)
        {...}
    }
    

    instantiate the observer in the controller, probably in application_controller, probably in a before_filter.

    class ApplicationController...
    function instantiateMyObserver()
    {
        new MyObserver('Part','Post',$Comment);  // <=Model-names as string or instances
        //or:
        $myObserver->observe($ModelInstance);       
        $myObserver->setObservedModels(ModelNames,...);
    }