Qiang Xue
12 years ago
7 changed files with 113 additions and 393 deletions
@ -0,0 +1,9 @@
|
||||
- `beforeInsert`. Raised before the record is saved. |
||||
By setting [[\yii\base\ModelEvent::isValid]] to be false, the normal [[save()]] will be stopped. |
||||
- `afterInsert`. Raised after the record is saved. |
||||
- `beforeUpdate`. Raised before the record is saved. |
||||
By setting [[\yii\base\ModelEvent::isValid]] to be false, the normal [[save()]] will be stopped. |
||||
- `afterUpdate`. Raised after the record is saved. |
||||
- `beforeDelete`. Raised before the record is deleted. |
||||
By setting [[\yii\base\ModelEvent::isValid]] to be false, the normal [[delete()]] process will be stopped. |
||||
- `afterDelete`. Raised after the record is deleted. |
@ -1,60 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* ModelBehavior class file. |
||||
* |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright © 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\base; |
||||
|
||||
/** |
||||
* ModelBehavior class. |
||||
* |
||||
* ModelBehavior is a base class for behaviors that are attached to a model object. |
||||
* The model should be an instance of [[Model]] or its child classes. |
||||
* |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
class ModelBehavior extends Behavior |
||||
{ |
||||
/** |
||||
* Declares event handlers for the owner's events. |
||||
* The default implementation returns the following event handlers: |
||||
* |
||||
* - `beforeValidate` event |
||||
* - `afterValidate` event |
||||
* |
||||
* You may override these event handler methods to respond to the corresponding owner events. |
||||
* @return array events (array keys) and the corresponding event handler methods (array values). |
||||
*/ |
||||
public function events() |
||||
{ |
||||
return array( |
||||
'beforeValidate' => 'beforeValidate', |
||||
'afterValidate' => 'afterValidate', |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `beforeValidate` event. |
||||
* Override this method if you want to handle the `beforeValidate` event of the [[owner]]. |
||||
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter |
||||
* to be false to cancel the validation process. |
||||
* @param ModelEvent $event event parameter |
||||
*/ |
||||
public function beforeValidate($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `afterValidate` event. |
||||
* Override this method if you want to handle the `beforeValidate` event of the [[owner]]. |
||||
* @param Event $event event parameter |
||||
*/ |
||||
public function afterValidate($event) |
||||
{ |
||||
} |
||||
} |
@ -1,102 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* ActiveRecordBehavior class file. |
||||
* |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright © 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\db; |
||||
|
||||
use yii\base\ModelBehavior; |
||||
|
||||
/** |
||||
* ActiveRecordBehavior is the base class for behaviors that can be attached to [[ActiveRecord]]. |
||||
* |
||||
* Compared to [[\yii\base\ModelBehavior]], ActiveRecordBehavior responds to more events |
||||
* that are specific to [[ActiveRecord]]. |
||||
* |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
class ActiveRecordBehavior extends ModelBehavior |
||||
{ |
||||
/** |
||||
* Declares events and the corresponding event handler methods. |
||||
* If you override this method, make sure you merge the parent result to the return value. |
||||
* @return array events (array keys) and the corresponding event handler methods (array values). |
||||
* @see \yii\base\Behavior::events() |
||||
*/ |
||||
public function events() |
||||
{ |
||||
return array_merge(parent::events(), array( |
||||
'beforeInsert' => 'beforeInsert', |
||||
'afterInsert' => 'afterInsert', |
||||
'beforeUpdate' => 'beforeUpdate', |
||||
'afterUpdate' => 'afterUpdate', |
||||
'beforeDelete' => 'beforeDelete', |
||||
'afterDelete' => 'afterDelete', |
||||
)); |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `beforeInsert` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter |
||||
* to be false to quit the ActiveRecord inserting process. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function beforeInsert($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `afterInsert` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function afterInsert($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `beforeUpdate` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter |
||||
* to be false to quit the ActiveRecord updating process. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function beforeUpdate($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `afterUpdate` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function afterUpdate($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `beforeDelete` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter |
||||
* to be false to quit the ActiveRecord deleting process. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function beforeDelete($event) |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* Responds to the owner's `afterDelete` event. |
||||
* Overrides this method if you want to handle the corresponding event of the owner. |
||||
* @param \yii\base\ModelEvent $event event parameter |
||||
*/ |
||||
public function afterDelete($event) |
||||
{ |
||||
} |
||||
} |
Loading…
Reference in new issue