Yii Framework Forum: Documentation on Component Event lacking - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Documentation on Component Event lacking Rate Topic: -----

#1 User is offline   zdenekca 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-May 12

Posted 04 May 2012 - 02:55 PM

Hi,

I am new to Yii (but not PHP or programming) and I found overall Yii documentation pretty good.

However the "Component Event" section in 'Component' chapter of Yii Guide is lacking overall explanation of how things flow and how actions are attached to events:

http://www.yiiframew...asics.component

I found a pretty good explanation of the component events here:

http://www.yiiframew...haviors-events/

Could you take some of the ideas that show how the event flows (with examples?) and add them to the guide's page on component events?


Based on the second link I think this would help to note as an example in the Yii Guide (or as a page comment):

To invoke action 'hello' when a new user is created we define an event 'onNewUser' and attach it to the 'hello' action:

i) define the event:

public function onNewUser($event)
{
$this->raiseEvent('onNewUser', $event); //raises the event
}

ii) define actions executed upon event by defining a handler (one or more):

public function hello($event)
{
$user = $event->sender;
var_dump($user->firstname, $user->lastname);
}

iii) attach event to action(s):

$model->onNewUser = array($this, 'hello');

or as an anonymous function:

$model->onNewUser = function($event) {
$this->raiseEvent('onNewUser', $event); //raises the event
}

iv) trigger event:

$event = new CModelEvent($this);
$this->onNewUser($event);


Thank you,
Zdenek
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 05 May 2012 - 01:44 AM

NOTE: moved to proper section (Feature request instead of General Discussion for Yii 1.1.x)
Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users