The php_trait model works in conjunction with the php_class model and is used to generate traits that can be used by various classes. Traits are collections of properties and methods that can be used by any number of classes. Unlike inheritance, which only allows one parent class, a class can use any number of trait definitions.
Defining traits is very similar to creating classes. Therefore, to learn how to define properties and methods within your trait definitions please review the php_class help.
Including the trait Definition
Traits defined using the php_trait model are generated into the trait subfolder of the main classes folder. Therefore, to incorporate traits defined within system you first have to require the trait using:
If the trait is defined within the current site, it should be included using:
In each case, tname is the name of the trait to be used.
The reference should be defined within the Before Class definition as shown.
Adding the use Statement
Within the Custom Code section, set the Section Type to be use and set the Location to be After Last Sibling. Enter the full use statement within the Custom Code column as shown:
Sorting Properties and Functions
You can sort both properties and functions (methods) by using the sort command. To only sort properties you can enter the command sort properties. To only sort functions, enter the command sort functions.