CAction

优质
小牛编辑
127浏览
2023-12-01
所有包 | 属性 | 方法
system.web.actions
继承abstract class CAction » CComponent
实现IAction
子类CCaptchaAction, CInlineAction, CViewAction, CWebServiceAction
源自1.0
版本$Id: CAction.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/web/actions/CAction.php
CAction是所有控制器动作类的基类。

CAction用分开的类文件提供了一个分割一个复杂的控制器 到几个简单的动作的途径。

派生类必须实现run()方法, 当action被请求时由controller发起。

一个action实例能通过controller属性访问它的控制器。

公共属性

隐藏继承属性

属性类型描述定义在
controllerCController拥有这个动作的控制器。CAction
idstring动作的ID。CAction

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造方法。CAction
__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
getController()返回拥有这个动作的控制器。CAction
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getId()返回动作的ID。CAction
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
raiseEvent()发起一个事件。CComponent
runWithParams()运行带有请求参数的对象。CAction

受保护方法

隐藏继承方法

方法描述定义在
runWithParamsInternal()执行一个带有命名参数的对象的方法。CAction

属性详细

controller 属性 只读 public CController getController()

拥有这个动作的控制器。

id 属性 只读 public string getId()

动作的ID。

方法详细

__construct() 方法
public void __construct(CController $controller, string $id)
$controllerCController拥有这个动作的控制器。
$idstring动作的ID。
源码: framework/web/actions/CAction.php#40 (显示) publicfunction__construct($controller,$id)
{
$this->_controller=$controller;
$this->_id=$id;
}

构造方法。

getController() 方法
public CController getController()
{return}CController拥有这个动作的控制器。
源码: framework/web/actions/CAction.php#49 (显示) publicfunctiongetController()
{
return$this->_controller;
}
getId() 方法
public string getId()
{return}string动作的ID。
源码: framework/web/actions/CAction.php#57 (显示) publicfunctiongetId()
{
return$this->_id;
}
runWithParams() 方法 (可用自 v1.1.7)
public boolean runWithParams(array $params)
$paramsarray请求参数(键名=>键值)
{return}boolean命名参数是否有效的
源码: framework/web/actions/CAction.php#69 (显示) publicfunctionrunWithParams($params)
{
$method=newReflectionMethod($this,'run');
if($method->getNumberOfParameters()>0)
return$this->runWithParamsInternal($this,$method,$params);
else
return$this->run();
}

运行带有请求参数的对象。 这个方法通过CController::runAction()内部调用。

runWithParamsInternal() 方法 (可用自 v1.1.7)
protected boolean runWithParamsInternal(mixed $object, ReflectionMethod $method, array $params)
$objectmixed要执行的对象的方法
$methodReflectionMethod方法映射
$paramsarray命名参数
{return}boolean命名参数是否有效的
源码: framework/web/actions/CAction.php#87 (显示) protectedfunctionrunWithParamsInternal($object,$method,$params)
{
$ps=array();
foreach($method->getParameters()as$i=>$param)
{
$name=$param->getName();
if(isset($params[$name]))
{
if($param->isArray())
$ps[]=is_array($params[$name])?$params[$name]:array($params[$name]);
elseif(!is_array($params[$name]))
$ps[]=$params[$name];
else
returnfalse;
}
elseif($param->isDefaultValueAvailable())
$ps[]=$param->getDefaultValue();
else
returnfalse;
}
$method->invokeArgs($object,$ps);
returntrue;
}

执行一个带有命名参数的对象的方法。 这个方法是内部使用。