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
46041d0c
Commit
46041d0c
authored
Jun 19, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #3280: Support dynamically attaching anonymous behaviors
parent
0087339a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
concept-behaviors.md
docs/guide/concept-behaviors.md
+10
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Component.php
framework/base/Component.php
+13
-5
No files found.
docs/guide/concept-behaviors.md
View file @
46041d0c
...
@@ -126,6 +126,16 @@ $component->attachBehavior('myBehavior3', [
...
@@ -126,6 +126,16 @@ $component->attachBehavior('myBehavior3', [
]);
]);
```
```
You may attach multiple behaviors at once by using the
[
[yii\base\Component::attachBehaviors()
]
] method.
For example,
```
php
$component
->
attachBehaviors
([
'myBehavior1'
=>
new
MyBehavior
,
// a named behavior
MyBehavior
::
className
(),
// an anonymous behavior
]);
```
You may also attach behaviors through
[
configurations
](
concept-configurations.md
)
. For more details, please
You may also attach behaviors through
[
configurations
](
concept-configurations.md
)
. For more details, please
refer to the
[
Configurations
](
concept-configurations.md#configuration-format
)
section.
refer to the
[
Configurations
](
concept-configurations.md#configuration-format
)
section.
...
...
framework/CHANGELOG.md
View file @
46041d0c
...
@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
...
@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
-
Enh #3232: Added
`export()`
and
`exportAsString()`
methods to
`yii\helpers\BaseVarDumper`
(klimov-paul)
-
Enh #3232: Added
`export()`
and
`exportAsString()`
methods to
`yii\helpers\BaseVarDumper`
(klimov-paul)
-
Enh #3244: Allow logging complex data such as arrays and object via the log system (cebe)
-
Enh #3244: Allow logging complex data such as arrays and object via the log system (cebe)
-
Enh #3252: Added support for case insensitive matching using ILIKE to PostgreSQL QueryBuilder (cebe)
-
Enh #3252: Added support for case insensitive matching using ILIKE to PostgreSQL QueryBuilder (cebe)
-
Enh #3280: Support dynamically attaching anonymous behaviors (qiangxue)
-
Enh #3284: Added support for checking multiple ETags by
`yii\filters\HttpCache`
(qiangxue)
-
Enh #3284: Added support for checking multiple ETags by
`yii\filters\HttpCache`
(qiangxue)
-
Enh #3298: Supported configuring
`View::theme`
using a class name (netyum, qiangxue)
-
Enh #3298: Supported configuring
`View::theme`
using a class name (netyum, qiangxue)
-
Enh #3328:
`BaseMailer`
generates better text body from html body (armab)
-
Enh #3328:
`BaseMailer`
generates better text body from html body (armab)
...
...
framework/base/Component.php
View file @
46041d0c
...
@@ -660,7 +660,9 @@ class Component extends Object
...
@@ -660,7 +660,9 @@ class Component extends Object
/**
/**
* Attaches a behavior to this component.
* Attaches a behavior to this component.
* @param string $name the name of the behavior.
* @param string|integer $name the name of the behavior. If this is an integer, it means the behavior
* is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name
* will be detached first.
* @param string|array|Behavior $behavior the behavior to be attached
* @param string|array|Behavior $behavior the behavior to be attached
* @return Behavior the attached behavior.
* @return Behavior the attached behavior.
*/
*/
...
@@ -669,11 +671,17 @@ class Component extends Object
...
@@ -669,11 +671,17 @@ class Component extends Object
if
(
!
(
$behavior
instanceof
Behavior
))
{
if
(
!
(
$behavior
instanceof
Behavior
))
{
$behavior
=
Yii
::
createObject
(
$behavior
);
$behavior
=
Yii
::
createObject
(
$behavior
);
}
}
if
(
isset
(
$this
->
_behaviors
[
$name
]))
{
if
(
is_int
(
$name
))
{
$this
->
_behaviors
[
$name
]
->
detach
();
$behavior
->
attach
(
$this
);
$this
->
_behaviors
[]
=
$behavior
;
}
else
{
if
(
isset
(
$this
->
_behaviors
[
$name
]))
{
$this
->
_behaviors
[
$name
]
->
detach
();
}
$behavior
->
attach
(
$this
);
$this
->
_behaviors
[
$name
]
=
$behavior
;
}
}
$behavior
->
attach
(
$this
);
return
$
this
->
_behaviors
[
$name
]
=
$
behavior
;
return
$behavior
;
}
}
}
}
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