1<?php 2/** 3 * CActiveRecordBehavior class file. 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.yiiframework.com/ 7 * @copyright Copyright © 2008-2010 Yii Software LLC 8 * @license http://www.yiiframework.com/license/ 9 */ 10 11/** 12 * CActiveRecordBehavior is the base class for behaviors that can be attached to {@link CActiveRecord}. 13 * Compared with {@link CModelBehavior}, CActiveRecordBehavior attaches to more events 14 * that are only defined by {@link CActiveRecord}. 15 * 16 * @author Qiang Xue <qiang.xue@gmail.com> 17 * @version $Id: CActiveRecordBehavior.php 1678 2010-01-07 21:02:00Z qiang.xue $ 18 * @package system.db.ar 19 * @since 1.0.2 20 */ 21class CActiveRecordBehavior extends CModelBehavior 22{ 23 /** 24 * Declares events and the corresponding event handler methods. 25 * If you override this method, make sure you merge the parent result to the return value. 26 * @return array events (array keys) and the corresponding event handler methods (array values). 27 * @see CBehavior::events 28 */ 29 public function events() 30 { 31 return array_merge(parent::events(), array( 32 'onBeforeSave'=>'beforeSave', 33 'onAfterSave'=>'afterSave', 34 'onBeforeDelete'=>'beforeDelete', 35 'onAfterDelete'=>'afterDelete', 36 'onAfterConstruct'=>'afterConstruct', 37 'onBeforeFind'=>'beforeFind', 38 'onAfterFind'=>'afterFind', 39 )); 40 } 41 42 /** 43 * Responds to {@link CActiveRecord::onBeforeSave} event. 44 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 45 * You may set {@link CModelEvent::isValid} to be false to quit the saving process. 46 * @param CModelEvent event parameter 47 */ 48 public function beforeSave($event) 49 { 50 } 51 52 /** 53 * Responds to {@link CActiveRecord::onAfterSave} event. 54 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 55 * @param CModelEvent event parameter 56 */ 57 public function afterSave($event) 58 { 59 } 60 61 /** 62 * Responds to {@link CActiveRecord::onBeforeDelete} event. 63 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 64 * You may set {@link CModelEvent::isValid} to be false to quit the deletion process. 65 * @param CEvent event parameter 66 */ 67 public function beforeDelete($event) 68 { 69 } 70 71 /** 72 * Responds to {@link CActiveRecord::onAfterDelete} event. 73 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 74 * @param CEvent event parameter 75 */ 76 public function afterDelete($event) 77 { 78 } 79 80 /** 81 * Responds to {@link CActiveRecord::onAfterConstruct} event. 82 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 83 * @param CEvent event parameter 84 */ 85 public function afterConstruct($event) 86 { 87 } 88 89 /** 90 * Responds to {@link CActiveRecord::onBeforeFind} event. 91 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 92 * @param CEvent event parameter 93 * @since 1.0.9 94 */ 95 public function beforeFind($event) 96 { 97 } 98 99 /** 100 * Responds to {@link CActiveRecord::onAfterFind} event. 101 * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. 102 * @param CEvent event parameter 103 */ 104 public function afterFind($event) 105 { 106 } 107} 108