Dear all,
I am trying to integrate email notification function into an extension called "Comment-module"
http://www.yiiframework.com/extension/comment-module
In this extension…There is an event raised when a new comment is added.
Here is the codes in its Comment-Module.php
/**
* This event is raised after a new comment has been added
*
* @param $comment
* @param $model
*/
public function onNewComment($comment, $model)
{
$event = new CommentEvent();
$event->comment = $comment;
$event->commentedModel = $model;
$this->raiseEvent('onNewComment', $event);
}
Here is the "commentEvent.php"
class CommentEvent extends CEvent
{
/**
* @var Comment the comment related to this event
*/
public $comment = null;
/**
* @var CActiveRecord the commented object if available
*/
public $commentedModel = null;
}
I know how to deal with events in Gii-generated models and controllers…But I have no idea about how to do this in an extension…
How can I trigger this event in an extension…?
I tried to add some codes like below in this extension’s Comment Controller—actionAddComment.
(My model is called Questions)
$questions=Questions::model()->findByPk(7); //just a example
$notifier = new Notifier(); //I have a Notifier.php in protected/components to send emails.
$questions->onNewComment = array($notifier,'comment');
but not works…shouldn’t i trigger the event here?
I do have the following codes in my Questions model:
public function behaviors()
{
return array(
'commentable' => array(
'class' => 'ext.comment-module.behaviors.CommentableBehavior',
// name of the table created in last step
'mapTable' => 'questions_comments_nm',
// name of column to related model id in mapTable
'mapRelatedColumn' => 'questionsId'
));
}
Any ideas…?
Thanks so much…!!!
Best,
jiaming