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
d5a79df6
Commit
d5a79df6
authored
Jul 04, 2014
by
Larry Ullman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a "handling component events" section
parent
48a8df59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
concept-behaviors.md
docs/guide/concept-behaviors.md
+9
-6
No files found.
docs/guide/concept-behaviors.md
View file @
d5a79df6
...
@@ -51,8 +51,11 @@ Because this class is a behavior, when it is attached to a component, that compo
...
@@ -51,8 +51,11 @@ Because this class is a behavior, when it is attached to a component, that compo
> Tip: Within a behavior, you can access the component that the behavior is attached to through the [[yii\base\Behavior::owner]] property.
> Tip: Within a behavior, you can access the component that the behavior is attached to through the [[yii\base\Behavior::owner]] property.
Handling Component Events
------------------
If a behavior needs to respond to the events triggered by the component it is attached to, it should override the
If a behavior needs to respond to the events triggered by the component it is attached to, it should override the
[
[yii\base\Behavior::events()
]
] method. For example
,
[
[yii\base\Behavior::events()
]
] method. For example
:
```
php
```
php
namespace
app\components
;
namespace
app\components
;
...
@@ -79,12 +82,12 @@ class MyBehavior extends Behavior
...
@@ -79,12 +82,12 @@ class MyBehavior extends Behavior
```
```
The
[
[yii\base\Behavior::events()|events()
]
] method should return a list of events and their corresponding handlers.
The
[
[yii\base\Behavior::events()|events()
]
] method should return a list of events and their corresponding handlers.
The above example declares that the
[
[yii\db\ActiveRecord::EVENT_BEFORE_VALIDATE|EVENT_BEFORE_VALIDATE
]
] event
and
The above example declares that the
[
[yii\db\ActiveRecord::EVENT_BEFORE_VALIDATE|EVENT_BEFORE_VALIDATE
]
] event
exists and defines
its handler
`beforeValidate()`
. When specifying an event handler, you may use one of the following formats:
its handler
,
`beforeValidate()`
. When specifying an event handler, you may use one of the following formats:
*
a string that refers to the name of a method of the behavior class, like the example above
;
*
a string that refers to the name of a method of the behavior class, like the example above
*
an array of an object or class name, and a method name, e.g.,
`[$object, 'methodName']`
;
*
an array of an object or class name, and a method name
as a string (without parentheses)
, e.g.,
`[$object, 'methodName']`
;
*
an anonymous function
.
*
an anonymous function
The signature of an event handler should be as follows, where
`$event`
refers to the event parameter. Please refer
The signature of an event handler should be as follows, where
`$event`
refers to the event parameter. Please refer
to the
[
Events
](
concept-events.md
)
section for more details about events.
to the
[
Events
](
concept-events.md
)
section for more details about events.
...
...
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