I have a number of different models that have custom validation methods, some of which are shared across models.

Due to the combinations I can't use class inheritance to share those methods, so I wondered if traits are supported and if so, what the convention would be?


Traits are just a PHP thing not related to Craft at all so yes, you could use them. But you'd be limiting your plugin to PHP 5.4+ only since that's when they were introduced.

Craft 2.x supports back to PHP 5.3.

You might also want to look at Yii's Behaviors, which have similar functionality to traits and works with PHP 5.3.

Craft 2.x uses a few behaviors of its own.

  • Thanks - I wasn't aware of behaviours so will take a look at that first. – Russ Back Apr 8 '15 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.