Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
48c7e328
Commit
48c7e328
authored
Apr 30, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished behavior guide [skip ci]
parent
2e892c42
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
basic-behaviors.md
docs/guide/basic-behaviors.md
+0
-0
basic-configs.md
docs/guide/basic-configs.md
+24
-0
Behavior.php
framework/base/Behavior.php
+2
-2
No files found.
docs/guide/basic-behaviors.md
View file @
48c7e328
This diff is collapsed.
Click to expand it.
docs/guide/basic-configs.md
View file @
48c7e328
...
@@ -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.
framework/base/Behavior.php
View file @
48c7e328
...
@@ -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',
* ]
* ]
* ~~~
* ~~~
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment