Skip to content

Commit a201adb

Browse files
author
igor
committed
add CommentModel to CommentEvent
1 parent 1cbc050 commit a201adb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

controllers/DefaultController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function actionCreate($entity)
6969
$model = new $commentModelClass;
7070
$model->setAttributes($entityData);
7171
if ($model->load(Yii::$app->request->post()) && $model->save()) {
72+
$event->setCommentModel($model);
7273
$this->trigger(self::EVENT_AFTER_CREATE, $event);
7374
return ['status' => 'success'];
7475
} else {

events/CommentEvent.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use yii\base\Event;
66
use yii\web\User;
7+
use yii2mod\comments\models\CommentModel;
78

89
/**
910
* Class CommentEvent
@@ -16,6 +17,11 @@ class CommentEvent extends Event
1617
*/
1718
private $_user;
1819

20+
/**
21+
* @var CommentModel
22+
*/
23+
private $_commentModel;
24+
1925
/**
2026
* @return User
2127
*/
@@ -31,4 +37,20 @@ public function setUser(User $user)
3137
{
3238
$this->_user = $user;
3339
}
40+
41+
/**
42+
* @return CommentModel
43+
*/
44+
public function getCommentModel()
45+
{
46+
return $this->_commentModel;
47+
}
48+
49+
/**
50+
* @param CommentModel $commentModel
51+
*/
52+
public function setCommentModel(CommentModel $commentModel)
53+
{
54+
$this->_commentModel = $commentModel;
55+
}
3456
}

0 commit comments

Comments
 (0)