Commit 48c7e328 by Qiang Xue

Finished behavior guide [skip ci]

parent 2e892c42
...@@ -178,3 +178,27 @@ return [ ...@@ -178,3 +178,27 @@ return [
], ],
]; ];
``` ```
### Attaching behaviors from config
One can attach a behavior to a component when configuring it with a configuration array. The syntax is like the
following:
```php
return [
// ...
'components' => [
'myComponent' => [
// ...
'as tree' => [
'class' => 'Tree',
'root' => 0,
],
],
],
];
```
In the config above `as tree` stands for attaching a behavior named `tree`, and the array will be passed to [[\Yii::createObject()]]
to create the behavior object.
...@@ -46,8 +46,8 @@ class Behavior extends \yii\base\Object ...@@ -46,8 +46,8 @@ class Behavior extends \yii\base\Object
* *
* ~~~ * ~~~
* [ * [
* Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate', * Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
* Model::EVENT_AFTER_VALIDATE => 'myAfterValidate', * Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
* ] * ]
* ~~~ * ~~~
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment