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
ed157ae1
Commit
ed157ae1
authored
Mar 31, 2012
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better example for component events. Button and click are too clientside-like.
parent
b163f2a4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
Component.php
framework/base/Component.php
+9
-9
No files found.
framework/base/Component.php
View file @
ed157ae1
...
...
@@ -16,8 +16,8 @@ namespace yii\base;
* the *property* feature which is implemented in its parent class [[Object]].
*
* Event is a way to "inject" custom code into existing code at certain places.
* For example, a
button object can trigger a "click" event when the user click
s
*
on the button
. We can write custom code and attach it to this event so that
* For example, a
comment object can trigger an "add" event when the user add
s
*
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.
*
* An event is identified by a name (unique within the class it is defined).
...
...
@@ -30,18 +30,18 @@ namespace yii\base;
* To attach an event handler to an event, call [[on()]]. For example,
*
* ~~~
* $
button->on('click
', function($event) {
*
echo "I'm clicked!";
* $
comment->on('add
', function($event) {
*
// send email notification
* });
* ~~~
*
* In the above, we attach an anonymous function to the "
click" event of the button
.
* In the above, we attach an anonymous function to the "
add" event of the comment
.
* Valid event handlers include:
*
* - anonymous function: `function($event) { ... }`
* - object method: `array($object, 'handle
OnClick
')`
* - static method: `array('Page', 'handle
OnClick
')`
* - global function: `'handle
OnClick
'`
* - object method: `array($object, 'handle
Add
')`
* - static method: `array('Page', 'handle
Add
')`
* - global function: `'handle
Add
'`
*
* The signature of an event handler should be like the following:
* ~~~
...
...
@@ -55,7 +55,7 @@ namespace yii\base;
* this object to attach/detach event handlers, or adjust their relative orders.
*
* ~~~
* $handlers = $
button->getEventHandlers('click
');
* $handlers = $
comment->getEventHandlers('add
');
* $handlers->insertAt(0, $callback); // attach a handler as the first one
* $handlers[] = $callback; // attach a handler as the last one
* unset($handlers[0]); // detach the first handler
...
...
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