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
Hide 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;
...
@@ -16,8 +16,8 @@ namespace yii\base;
* the *property* feature which is implemented in its parent class [[Object]].
* 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.
* 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
* For example, a
comment object can trigger an "add" event when the user add
s
*
on the button
. We can write custom code and attach it to this event so that
*
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.
* 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).
* An event is identified by a name (unique within the class it is defined).
...
@@ -30,18 +30,18 @@ namespace yii\base;
...
@@ -30,18 +30,18 @@ namespace yii\base;
* To attach an event handler to an event, call [[on()]]. For example,
* To attach an event handler to an event, call [[on()]]. For example,
*
*
* ~~~
* ~~~
* $
button->on('click
', function($event) {
* $
comment->on('add
', function($event) {
*
echo "I'm clicked!";
*
// 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:
* Valid event handlers include:
*
*
* - anonymous function: `function($event) { ... }`
* - anonymous function: `function($event) { ... }`
* - object method: `array($object, 'handle
OnClick
')`
* - object method: `array($object, 'handle
Add
')`
* - static method: `array('Page', 'handle
OnClick
')`
* - static method: `array('Page', 'handle
Add
')`
* - global function: `'handle
OnClick
'`
* - global function: `'handle
Add
'`
*
*
* The signature of an event handler should be like the following:
* The signature of an event handler should be like the following:
* ~~~
* ~~~
...
@@ -55,7 +55,7 @@ namespace yii\base;
...
@@ -55,7 +55,7 @@ namespace yii\base;
* this object to attach/detach event handlers, or adjust their relative orders.
* 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->insertAt(0, $callback); // attach a handler as the first one
* $handlers[] = $callback; // attach a handler as the last one
* $handlers[] = $callback; // attach a handler as the last one
* unset($handlers[0]); // detach the first handler
* 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