Commit edb95052 by Carsten Brandt

use an AfterSaveEvent class to be consistent

parent b0fb04ef
......@@ -8,9 +8,7 @@
namespace yii\base;
/**
* ModelEvent class.
*
* ModelEvent represents the parameter needed by model events.
* ModelEvent represents the parameter needed by [[Model]] events.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
......
......@@ -88,6 +88,7 @@ return [
'yii\db\ActiveRecord' => YII_PATH . '/db/ActiveRecord.php',
'yii\db\ActiveRecordInterface' => YII_PATH . '/db/ActiveRecordInterface.php',
'yii\db\ActiveRelationTrait' => YII_PATH . '/db/ActiveRelationTrait.php',
'yii\db\AfterSaveEvent' => YII_PATH . '/db/AfterSaveEvent.php',
'yii\db\BaseActiveRecord' => YII_PATH . '/db/BaseActiveRecord.php',
'yii\db\BatchQueryResult' => YII_PATH . '/db/BatchQueryResult.php',
'yii\db\ColumnSchema' => YII_PATH . '/db/ColumnSchema.php',
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db;
use yii\base\Event;
/**
* AfterSaveEvent represents the information available in [[ActiveRecord::EVENT_AFTER_INSERT]] and [[ActiveRecord::EVENT_AFTER_UPDATE]].
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class AfterSaveEvent extends Event
{
/**
* @var array The attribute values that had changed and were saved.
*/
public $changedAttributes;
}
......@@ -867,17 +867,17 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
/**
* This method is called at the end of inserting or updating a record.
* The default implementation will trigger an [[EVENT_AFTER_INSERT]] event when `$insert` is true,
* or an [[EVENT_AFTER_UPDATE]] event if `$insert` is false.
* or an [[EVENT_AFTER_UPDATE]] event if `$insert` is false. The event class used is [[AfterSaveEvent]].
* When overriding this method, make sure you call the parent implementation so that
* the event is triggered.
* @param boolean $insert whether this method called while inserting a record.
* @param array $changedAttributes the attribute values that have changed during save.
* If false, it means the method is called while updating a record.
* @param array $changedAttributes The attribute values that had changed and were saved.
*/
public function afterSave($insert, $changedAttributes)
{
$this->trigger($insert ? self::EVENT_AFTER_INSERT : self::EVENT_AFTER_UPDATE, new ModelEvent([
'data' => ['changedAttributes' => $changedAttributes]
$this->trigger($insert ? self::EVENT_AFTER_INSERT : self::EVENT_AFTER_UPDATE, new AfterSaveEvent([
'changedAttributes' => $changedAttributes
]));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment