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