CModelBehavior.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * CModelBehavior 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. * CModelBehavior is a base class for behaviors that are attached to a model component.
  12. * The model should extend from {@link CModel} or its child classes.
  13. *
  14. * @property CModel $owner The owner model that this behavior is attached to.
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @package system.base
  18. */
  19. class CModelBehavior extends CBehavior
  20. {
  21. /**
  22. * Declares events and the corresponding event handler methods.
  23. * The default implementation returns 'onAfterConstruct', 'onBeforeValidate' and 'onAfterValidate' events and handlers.
  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(
  31. 'onAfterConstruct'=>'afterConstruct',
  32. 'onBeforeValidate'=>'beforeValidate',
  33. 'onAfterValidate'=>'afterValidate',
  34. );
  35. }
  36. /**
  37. * Responds to {@link CModel::onAfterConstruct} event.
  38. * Override this method and make it public if you want to handle the corresponding event
  39. * of the {@link CBehavior::owner owner}.
  40. * @param CEvent $event event parameter
  41. */
  42. protected function afterConstruct($event)
  43. {
  44. }
  45. /**
  46. * Responds to {@link CModel::onBeforeValidate} event.
  47. * Override this method and make it public if you want to handle the corresponding event
  48. * of the {@link owner}.
  49. * You may set {@link CModelEvent::isValid} to be false to quit the validation process.
  50. * @param CModelEvent $event event parameter
  51. */
  52. protected function beforeValidate($event)
  53. {
  54. }
  55. /**
  56. * Responds to {@link CModel::onAfterValidate} event.
  57. * Override this method and make it public if you want to handle the corresponding event
  58. * of the {@link owner}.
  59. * @param CEvent $event event parameter
  60. */
  61. protected function afterValidate($event)
  62. {
  63. }
  64. }