A behavior can be used to enhance the functionality of an existing component without modifying its code. In particular, it can "inject" its own methods and properties into the component and make them directly accessible via the component. It can also respond to the events triggered in the component and thus intercept the normal code execution.
行为(Behaviors)
在Yii框架中,行为实现了Mixin模式。它们可以增强组件的功能,但是不用修改组件的代码; 行为还可以响应在组件中触发的事件,从而拦截正常代码的执行。与PHPTraits
不同,behaviors
可以在代码运行时,附加到类。