CActiveRecordBehavior.php 3.4 KB

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