CFilter

CDbHttpSession

Yii Framework v1.1.10 类参考

CFilter

system.web.filters
继承 class CFilter » CComponent
实现 IFilter
子类 CAccessControlFilter, CInlineFilter
源自 1.0
版本 $Id: CFilter.php 2799 2011-01-01 19:31:13Z qiang.xue $
源码 framework/web/filters/CFilter.php
CFilter是所有过滤器的基类。

过滤器可用于动作执行之前和之后。 它可以修改动作的上下文执行, 或者修改动作所产生的结果。

重写preFilter()指定在动作之前执行 的过滤逻辑,重写postFilter()在动作之后的执行过滤逻辑。

公共方法

隐藏继承方法

方法描述定义在
__call() 如果类中没有调的方法名,则调用这个方法。 CComponent
__get() 返回一个属性值、一个事件处理程序列表或一个行为名称。 CComponent
__isset() 检查一个属性是否为null。 CComponent
__set() 设置一个组件的属性值。 CComponent
__unset() 设置一个组件的属性为null。 CComponent
asa() 返回这个名字的行为对象。 CComponent
attachBehavior() 附加一个行为到组件。 CComponent
attachBehaviors() 附加一个行为列表到组件。 CComponent
attachEventHandler() 为事件附加一个事件处理程序。 CComponent
canGetProperty() 确定属性是否可读。 CComponent
canSetProperty() 确定属性是否可写。 CComponent
detachBehavior() 从组件中分离一个行为。 CComponent
detachBehaviors() 从组件中分离所有行为。 CComponent
detachEventHandler() 分离一个存在的事件处理程序。 CComponent
disableBehavior() 禁用一个附加行为。 CComponent
disableBehaviors() 禁用组件附加的所有行为。 CComponent
enableBehavior() 启用一个附加行为。 CComponent
enableBehaviors() 启用组件附加的所有行为。 CComponent
evaluateExpression() 计算一个PHP表达式,或根据组件上下文执行回调。 CComponent
filter() 执行过滤。 CFilter
getEventHandlers() 返回一个事件的附加处理程序列表。 CComponent
hasEvent() 确定一个事件是否定义。 CComponent
hasEventHandler() 检查事件是否有附加的处理程序。 CComponent
hasProperty() 确定属性是否被定义。 CComponent
init() 初始化过滤器。 CFilter
raiseEvent() 发起一个事件。 CComponent

受保护方法

隐藏继承方法

方法描述定义在
postFilter() 执行post操作过滤器。 CFilter
preFilter() 执行预操作过滤器。 CFilter

方法详细

filter() 方法
public void filter(CFilterChain $filterChain)
$filterChain CFilterChain 设置好的过滤器链。
源码: framework/web/filters/CFilter.php#37 (显示)
public function filter($filterChain)
{
    if(
$this->preFilter($filterChain))
    {
        
$filterChain->run();
        
$this->postFilter($filterChain);
    }
}

执行过滤。 默认实现的是调用preFilterpostFilter,子类 应该覆盖这个方法。如果子类需要覆盖这个方法, 要确定动作执行时调用 $filterChain->run()

init() 方法 (可用自 v1.1.4)
public void init()
源码: framework/web/filters/CFilter.php#53 (显示)
public function init()
{
}

初始化过滤器。 这个方法会在过滤器属性已经初始化, preFilter调用之前调用。 你可以覆盖这个方法以包含一些初始化的逻辑。

postFilter() 方法
protected void postFilter(CFilterChain $filterChain)
$filterChain CFilterChain 设置好的过滤器链。
源码: framework/web/filters/CFilter.php#72 (显示)
protected function postFilter($filterChain)
{
}

执行post操作过滤器。

preFilter() 方法
protected boolean preFilter(CFilterChain $filterChain)
$filterChain CFilterChain 设置好的过滤器链。
{return} boolean 过滤过程是否要继承, 并且动作将要执行。
源码: framework/web/filters/CFilter.php#63 (显示)
protected function preFilter($filterChain)
{
    return 
true;
}

执行预操作过滤器。

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.