Yii2 Bootstrap 3
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.

71 lines
1.9 KiB

13 years ago
<?php
/**
* Action class file.
13 years ago
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
13 years ago
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
13 years ago
use yii\util\ReflectionHelper;
13 years ago
/**
* Action is the base class for all controller action classes.
13 years ago
*
* Action provides a way to divide a complex controller into
13 years ago
* smaller actions in separate class files.
*
13 years ago
* Derived classes must implement a method named `run()`. This method
* will be invoked by the controller when the action is requested.
* The `run()` method can have parameters which will be filled up
* with user input values automatically according to their names.
13 years ago
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
13 years ago
*/
class Action extends Component
13 years ago
{
/**
* @var string ID of the action
13 years ago
*/
public $id;
13 years ago
/**
* @var Controller the controller that owns this action
13 years ago
*/
public $controller;
13 years ago
/**
13 years ago
* @param string $id the ID of this action
* @param Controller $controller the controller that owns this action
* @param array $config name-value pairs that will be used to initialize the object properties
13 years ago
*/
public function __construct($id, $controller, $config = array())
13 years ago
{
$this->id = $id;
$this->controller = $controller;
parent::__construct($config);
13 years ago
}
/**
13 years ago
* Runs this action with the specified parameters.
* This method is mainly invoked by the controller.
* @param array $params action parameters
* @return integer the exit status (0 means normal, non-zero means abnormal).
13 years ago
*/
13 years ago
public function runWithParams($params)
13 years ago
{
13 years ago
try {
13 years ago
$ps = ReflectionHelper::extractMethodParams($this, 'run', $params);
13 years ago
} catch (Exception $e) {
$this->controller->invalidActionParams($this, $e);
13 years ago
return 1;
13 years ago
}
13 years ago
if ($params !== $ps) {
$this->controller->extraActionParams($this, $ps, $params);
}
return (int)call_user_func_array(array($this, 'run'), $ps);
13 years ago
}
}