ModelBehavior.php 1.93 KB
Newer Older
w  
Qiang Xue committed
1 2
<?php
/**
w  
Qiang Xue committed
3
 * ModelBehavior class file.
w  
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
w  
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008-2012 Yii Software LLC
w  
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

w  
Qiang Xue committed
10 11
namespace yii\base;

w  
Qiang Xue committed
12
/**
w  
Qiang Xue committed
13 14 15 16 17
 * 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.
 *
w  
Qiang Xue committed
18
 * @author Qiang Xue <qiang.xue@gmail.com>
w  
Qiang Xue committed
19
 * @since 2.0
w  
Qiang Xue committed
20
 */
w  
Qiang Xue committed
21
class ModelBehavior extends Behavior
w  
Qiang Xue committed
22 23
{
	/**
w  
Qiang Xue committed
24
	 * Declares event handlers for owner's events.
w  
Qiang Xue committed
25
	 * The default implementation returns the following event handlers:
w  
Qiang Xue committed
26
	 *
Qiang Xue committed
27
	 * - `onAfterInit` event: [[afterInit]]
w  
Qiang Xue committed
28 29 30 31
	 * - `onBeforeValidate` event: [[beforeValidate]]
	 * - `onAfterValidate` event: [[afterValidate]]
	 *
	 * You may override these event handler methods to respond to the corresponding owner events.
w  
Qiang Xue committed
32 33 34 35 36
	 * @return array events (array keys) and the corresponding event handler methods (array values).
	 */
	public function events()
	{
		return array(
Qiang Xue committed
37
			'onAfterInit' => 'afterInit',
w  
Qiang Xue committed
38 39
			'onBeforeValidate' => 'beforeValidate',
			'onAfterValidate' => 'afterValidate',
w  
Qiang Xue committed
40 41 42 43
		);
	}

	/**
Qiang Xue committed
44
	 * Responds to [[Model::onAfterInit]] event.
Alex committed
45
	 * Override this method if you want to handle the corresponding event of the [[owner]].
w  
Qiang Xue committed
46
	 * @param Event $event event parameter
w  
Qiang Xue committed
47
	 */
Qiang Xue committed
48
	public function afterInit($event)
w  
Qiang Xue committed
49 50 51 52
	{
	}

	/**
w  
Qiang Xue committed
53
	 * Responds to [[Model::onBeforeValidate]] event.
Alex committed
54
	 * Override this method if you want to handle the corresponding event of the [[owner]].
Qiang Xue committed
55
	 * You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
w  
Qiang Xue committed
56
	 * to be false to cancel the validation process.
Qiang Xue committed
57
	 * @param ModelEvent $event event parameter
w  
Qiang Xue committed
58 59 60 61 62 63
	 */
	public function beforeValidate($event)
	{
	}

	/**
w  
Qiang Xue committed
64
	 * Responds to [[Model::onAfterValidate]] event.
Alex committed
65
	 * Override this method if you want to handle the corresponding event of the [[owner]].
w  
Qiang Xue committed
66
	 * @param Event $event event parameter
w  
Qiang Xue committed
67 68 69 70 71
	 */
	public function afterValidate($event)
	{
	}
}