我正在使用行为并动态添加它们,这是很好的工作。要添加行为,可以使用
$component->attachBehavior('myBehavior1', new MyBehavior);或
$component->attachBehavior('myBehavior2', MyBehavior::className());我不知道什么时候该用哪种方法,或者没有区别?有人能给我解释一下吗?
发布于 2014-10-20 09:15:05
没有区别:
http://www.yiiframework.com/doc-2.0/yii-base-component.html#attachBehavior()-detail
yii\base\Behavior attachBehavior( $name,$behavior ) $behavior (string\array)\base\ behavior (string\array\base\behavior)行为配置。这可以是以下内容之一:
https://stackoverflow.com/questions/26461347
复制相似问题