CAction
CAction is the base class for all controller action classes.
CAction provides a way to divide a complex controller into smaller actions in separate class files.
Derived classes must implement run() which is invoked by controller when the action is requested.
An action instance can access its controller via
controller property.
Public Properties
Property |
Type |
Description |
Defined By |
controller | CController | the controller who owns this action. | CAction |
id | string | id of this action | CAction |
Protected Methods
Method |
Description |
Defined By |
runWithParamsInternal() | Executes a method of an object with the supplied named parameters. | CAction |
Property Details
public CController getController()
the controller who owns this action.
public string getId()
id of this action
Method Details
public void __construct(CController $controller, string $id) |
$controller | CController | the controller who owns this action. |
$id | string | id of the action. |
Constructor.
public string getId() |
{return} | string | id of this action |
public boolean runWithParams(array $params) |
$params | array | the request parameters (name=>value) |
{return} | boolean | whether the request parameters are valid |
Source Code: framework/web/actions/CAction.php#70 (
show)
public function runWithParams($params)
{
$method=new ReflectionMethod($this, 'run');
if($method->getNumberOfParameters()>0)
return $this->runWithParamsInternal($this, $method, $params);
$this->run();
return true;
}
Runs the action with the supplied request parameters. This method is internally called by CController::runAction().
protected boolean runWithParamsInternal(mixed $object, ReflectionMethod $method, array $params) |
$object | mixed | the object whose method is to be executed |
$method | ReflectionMethod | the method reflection |
$params | array | the named parameters |
{return} | boolean | whether the named parameters are valid |
Source Code: framework/web/actions/CAction.php#89 (
show)
protected function runWithParamsInternal($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
return false;
}
elseif($param->isDefaultValueAvailable())
$ps[]=$param->getDefaultValue();
else
return false;
}
$method->invokeArgs($object,$ps);
return true;
}
Executes a method of an object with the supplied named parameters. This method is internally used.