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
edb95052
Commit
edb95052
authored
Jun 25, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use an AfterSaveEvent class to be consistent
parent
b0fb04ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
7 deletions
+30
-7
ModelEvent.php
framework/base/ModelEvent.php
+1
-3
classes.php
framework/classes.php
+1
-0
AfterSaveEvent.php
framework/db/AfterSaveEvent.php
+24
-0
BaseActiveRecord.php
framework/db/BaseActiveRecord.php
+4
-4
No files found.
framework/base/ModelEvent.php
View file @
edb95052
...
...
@@ -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
...
...
framework/classes.php
View file @
edb95052
...
...
@@ -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'
,
...
...
framework/db/AfterSaveEvent.php
0 → 100644
View file @
edb95052
<?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
;
}
framework/db/BaseActiveRecord.php
View file @
edb95052
...
...
@@ -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
Model
Event
([
'
data'
=>
[
'changedAttributes'
=>
$changedAttributes
]
$this
->
trigger
(
$insert
?
self
::
EVENT_AFTER_INSERT
:
self
::
EVENT_AFTER_UPDATE
,
new
AfterSave
Event
([
'
changedAttributes'
=>
$changedAttributes
]));
}
...
...
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