ModelBehavior.php 1.61 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
{
	/**
Qiang Xue committed
24
	 * Declares event handlers for the 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 28
	 * - `beforeValidate` event
	 * - `afterValidate` event
w  
Qiang Xue committed
29 30
	 *
	 * You may override these event handler methods to respond to the corresponding owner events.
w  
Qiang Xue committed
31 32 33 34 35
	 * @return array events (array keys) and the corresponding event handler methods (array values).
	 */
	public function events()
	{
		return array(
Qiang Xue committed
36 37
			'beforeValidate' => 'beforeValidate',
			'afterValidate' => 'afterValidate',
w  
Qiang Xue committed
38 39 40 41
		);
	}

	/**
Qiang Xue committed
42 43
	 * Responds to the owner's `beforeValidate` event.
	 * Override this method if you want to handle the `beforeValidate` event of the [[owner]].
Qiang Xue committed
44
	 * You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
w  
Qiang Xue committed
45
	 * to be false to cancel the validation process.
Qiang Xue committed
46
	 * @param ModelEvent $event event parameter
w  
Qiang Xue committed
47 48 49 50 51 52
	 */
	public function beforeValidate($event)
	{
	}

	/**
Qiang Xue committed
53 54
	 * Responds to the owner's `afterValidate` event.
	 * Override this method if you want to handle the `beforeValidate` event of the [[owner]].
w  
Qiang Xue committed
55
	 * @param Event $event event parameter
w  
Qiang Xue committed
56 57 58 59 60
	 */
	public function afterValidate($event)
	{
	}
}