You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

14 years ago
<?php
/**
14 years ago
* ModelBehavior class file.
14 years ago
*
* @link http://www.yiiframework.com/
14 years ago
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
14 years ago
* @license http://www.yiiframework.com/license/
*/
14 years ago
namespace yii\base;
14 years ago
/**
14 years ago
* 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.
*
14 years ago
* @author Qiang Xue <qiang.xue@gmail.com>
14 years ago
* @since 2.0
14 years ago
*/
14 years ago
class ModelBehavior extends Behavior
14 years ago
{
/**
14 years ago
* Declares event handlers for owner's events.
14 years ago
* The default implementation returns the following event handlers:
14 years ago
*
* - `onAfterConstruct` event: [[afterConstruct]]
14 years ago
* - `onInit` event: [[initModel]]
14 years ago
* - `onBeforeValidate` event: [[beforeValidate]]
* - `onAfterValidate` event: [[afterValidate]]
*
* You may override these event handler methods to respond to the corresponding owner events.
14 years ago
* @return array events (array keys) and the corresponding event handler methods (array values).
*/
public function events()
{
return array(
14 years ago
'onAfterConstruct' => 'afterConstruct',
14 years ago
'onInit' => 'initModel',
14 years ago
'onBeforeValidate' => 'beforeValidate',
'onAfterValidate' => 'afterValidate',
14 years ago
);
}
/**
14 years ago
* Responds to [[Model::onInit]] event.
* Overrides this method if you want to handle the corresponding event of the [[owner]].
* @param Event $event event parameter
*/
public function initModel($event)
{
}
/**
14 years ago
* Responds to [[Model::onAfterConstruct]] event.
* Overrides this method if you want to handle the corresponding event of the [[owner]].
* @param Event $event event parameter
14 years ago
*/
public function afterConstruct($event)
{
}
/**
14 years ago
* Responds to [[Model::onBeforeValidate]] event.
* Overrides this method if you want to handle the corresponding event of the [[owner]].
* You may set the [[ValidationEvent::isValid|isValid]] property of the event parameter
* to be false to cancel the validation process.
* @param ValidationEvent $event event parameter
14 years ago
*/
public function beforeValidate($event)
{
}
/**
14 years ago
* Responds to [[Model::onAfterValidate]] event.
* Overrides this method if you want to handle the corresponding event of the [[owner]].
* @param Event $event event parameter
14 years ago
*/
public function afterValidate($event)
{
}
}