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
c0d439ba
Commit
c0d439ba
authored
Jan 20, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Component documentation wording
parent
41e70551
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
Component.md
docs/api/base/Component.md
+10
-9
No files found.
docs/api/base/Component.md
View file @
c0d439ba
...
@@ -3,15 +3,15 @@ its parent class [[Object]].
...
@@ -3,15 +3,15 @@ its parent class [[Object]].
Event is a way to "inject" custom code into existing code at certain places. For example, a comment object can trigger
Event is a way to "inject" custom code into existing code at certain places. For example, a comment object can trigger
an "add" event when the user adds a comment. We can write custom code and attach it to this event so that when the event
an "add" event when the user adds a comment. We can write custom code and attach it to this event so that when the event
is triggered, our custom code will be executed.
is triggered
(i.e. comment will be added)
, our custom code will be executed.
An event is identified by a name
(unique within the class it is defined)
. Event names are
*case-sensitive*
.
An event is identified by a name
that should be unique within the class it is defined at
. Event names are
*case-sensitive*
.
An event can be attached with one or multiple PHP callbacks, called
*event handlers*
. One
can call
[
[trigger()
]
] to
One or multiple PHP callbacks, called
*event handlers*
, could be attached to event. You
can call
[
[trigger()
]
] to
raise an event. When an event is raised, the
attached event handlers will be invoked automatically in the order they a
re
raise an event. When an event is raised, the
event handlers will be invoked automatically in the order they we
re
attached
to the event
.
attached.
To attach an event handler to an event, call
[
[on()
]
]
. For example,
To attach an event handler to an event, call
[
[on()
]
]
:
~~~
~~~
$comment->on('add', function($event) {
$comment->on('add', function($event) {
...
@@ -19,7 +19,8 @@ $comment->on('add', function($event) {
...
@@ -19,7 +19,8 @@ $comment->on('add', function($event) {
});
});
~~~
~~~
In the above, we attach an anonymous function to the "add" event of the comment. Valid event handlers include:
In the above, we attach an anonymous function to the "add" event of the comment.
Valid event handlers include:
-
anonymous function:
`function($event) { ... }`
-
anonymous function:
`function($event) { ... }`
-
object method:
`array($object, 'handleAdd')`
-
object method:
`array($object, 'handleAdd')`
...
@@ -34,7 +35,7 @@ function foo($event)
...
@@ -34,7 +35,7 @@ function foo($event)
where
`$event`
is an
[
[Event
]
] object which includes parameters associated with the event.
where
`$event`
is an
[
[Event
]
] object which includes parameters associated with the event.
One
can also attach an event handler to an event when configuring a component with a configuration array. The syntax is
You
can also attach an event handler to an event when configuring a component with a configuration array. The syntax is
like the following:
like the following:
~~~
~~~
...
@@ -45,7 +46,7 @@ array(
...
@@ -45,7 +46,7 @@ array(
where
`on add`
stands for attaching an event to the
`add`
event.
where
`on add`
stands for attaching an event to the
`add`
event.
One
can call
[
[getEventHandlers()
]
] to retrieve all event handlers that are attached to a specified event. Because this
You
can call
[
[getEventHandlers()
]
] to retrieve all event handlers that are attached to a specified event. Because this
method returns a
[
[Vector
]
] object, we can manipulate this object to attach/detach event handlers, or adjust their
method returns a
[
[Vector
]
] object, we can manipulate this object to attach/detach event handlers, or adjust their
relative orders.
relative orders.
...
...
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