| 包 | system.base |
|---|---|
| 继承 | class CModelBehavior » CBehavior » CComponent |
| 实现 | IBehavior |
| 子类 | CActiveRecordBehavior |
| 版本 | $Id: CModelBehavior.PHP 3515 2011-12-28 12:29:24Z mDOMba $ |
| 源码 |
CModelBehavior是所有模型组件附加行为的基类。
模型类应该继承CModel或它的子类。
公共属性
| 属性 | 类型 | 描述 | 定义在 |
|---|---|---|---|
| enabled | boolean | 事件是否被启用。 | CBehavior |
| owner | CComponent | 获得附加行为的组件。 | CBehavior |
公共方法
| 方法 | 描述 | 定义在 |
|---|---|---|
| __call() | 如果类中没有调的方法名,则调用这个方法。 | CComponent |
| __get() | 返回一个属性值、一个事件处理程序列表或一个行为名称。 | CComponent |
| __isset() | 检查一个属性是否为null。 | CComponent |
| __set() | 设置一个组件的属性值。 | CComponent |
| __unset() | 设置一个组件的属性为null。 | CComponent |
| afterConstruct() | 响应CModel::onAfterConstruct事件。 | CModelBehavior |
| afterValidate() | 响应CModel::onAfterValidate事件。 | CModelBehavior |
| asa() | 返回这个名字的行为对象。 | CComponent |
| attach() | 附加事件处理程序到组件。 | CBehavior |
| attachBehavior() | 附加一个行为到组件。 | CComponent |
| attachBehaviors() | 附加一个行为列表到组件。 | CComponent |
| attachEventHandler() | 为事件附加一个事件处理程序。 | CComponent |
| beforeValidate() | 响应CModel::onBeforeValidate事件。 | CModelBehavior |
| canGetProperty() | 确定属性是否可读。 | CComponent |
| canSetProperty() | 确定属性是否可写。 | CComponent |
| detach() | 从组件分离行为对象。 | CBehavior |
| detachBehavior() | 从组件中分离一个行为。 | CComponent |
| detachBehaviors() | 从组件中分离所有行为。 | CComponent |
| detachEventHandler() | 分离一个存在的事件处理程序。 | CComponent |
| disableBehavior() | 禁用一个附加行为。 | CComponent |
| disableBehaviors() | 禁用组件附加的所有行为。 | CComponent |
| enableBehavior() | 启用一个附加行为。 | CComponent |
| enableBehaviors() | 启用组件附加的所有行为。 | CComponent |
| evaLuateExpression() | 计算一个PHP表达式,或根据组件上下文执行回调。 | CComponent |
| events() | 声明事件和相应的事件处理方法。 | CModelBehavior |
| getEnabled() | 返回事件是否被启用。 | CBehavior |
| getEventHandlers() | 返回一个事件的附加处理程序列表。 | CComponent |
| getOwner() | 返回获得附加行为的组件。 | CBehavior |
| hasEvent() | 确定一个事件是否定义。 | CComponent |
| hasEventHandler() | 检查事件是否有附加的处理程序。 | CComponent |
| hasProperty() | 确定属性是否被定义。 | CComponent |
| raiseEvent() | 发起一个事件。 | CComponent |
| setEnabled() | 设置是否启用行为 | CBehavior |
方法详细
afterConstruct()
方法
|
public void afterConstruct(CEvent $event)
| ||
| $event | CEvent | 事件参数 |
public function afterConstruct($event)
{
}
响应CModel::onAfterConstruct事件。 如果你想处理owner对应的事件,请重载此方法。
afterValidate()
方法
|
public void afterValidate(CEvent $event)
| ||
| $event | CEvent | 事件参数 |
public function afterValidate($event)
{
}
响应CModel::onAfterValidate事件。 如果你想处理owner对应的事件,请重载此方法。
beforeValidate()
方法
|
public void beforeValidate(CModelEvent $event)
| ||
| $event | CModelEvent | 事件参数 |
public function beforeValidate($event)
{
}
响应CModel::onBeforeValidate事件。 如果你想处理owner对应的事件,请重载此方法。 你可以设置CModelEvent::isValid为false退出验证过程。
events()
方法
|
public array events()
| ||
| {return} | array | 事件(数组键)对应的事件处理方法(数组值)。 |
public function events()
{
return array(
'onAfterConstruct'=>'afterConstruct',
'onBeforeValidate'=>'beforeValidate',
'onAfterValidate'=>'afterValidate',
);
}
声明事件和相应的事件处理方法。 默认实现了‘onAfterConstruct’,‘onBeforeValidate’和‘onAfterValidate’事件和事件处理。 如果你重载此方法,请确保合并父类的返回值。
参见
- CBehavior::events