How to handle multiple model behaviors #15379
Unanswered
wurst-hans
asked this question in
Q&A
Replies: 1 comment 6 replies
-
Hi Hans, just a couple of untested ideas:
|
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, I'm building a minimal bootstrap project as base for all my other projects. I thought about models behavior now. Additionally to the SoftDelete and Timestampable I want to create a behavior which logs changes on model columns to a dedicated table.
The best approach, I think, is to create something like traits for each behavior that can be added to every model if required. But I don't want to use traits like mentioned in Phalcon doc, which use events themselves. My traits should be recognized on initialization and added with
$this->addBehavior();
, for example:I think, having many models it can improve flexibility and configuration of models a lot when you just have to add multiple traits for enabling a (real) behavior.
Can anyone point me into right direction how to achieve this? Does the above make sense? Sure, for every new behavior (i.e. trait) the base model has to be extended. How can it be improved?
EDIT: I've seen
class_uses()
right now, which can be used...Beta Was this translation helpful? Give feedback.
All reactions