InlineAction.php 1.54 KB
Newer Older
Qiang Xue committed
1 2
<?php
/**
Qiang Xue committed
3
 * InlineAction class file.
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008 Yii Software LLC
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
10
namespace yii\base;
Qiang Xue committed
11 12

/**
Qiang Xue committed
13
 * InlineAction represents an action that is defined as a controller method.
Qiang Xue committed
14
 *
Qiang Xue committed
15 16
 * The name of the controller method is available via [[actionMethod]] which
 * is set by the [[controller]] who creates this action.
Qiang Xue committed
17 18
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
19
 * @since 2.0
Qiang Xue committed
20
 */
Qiang Xue committed
21
class InlineAction extends Action
Qiang Xue committed
22
{
Qiang Xue committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	/**
	 * @var string the controller method that  this inline action is associated with
	 */
	public $actionMethod;

	/**
	 * @param string $id the ID of this action
	 * @param Controller $controller the controller that owns this action
	 * @param string $actionMethod the controller method that  this inline action is associated with
	 * @param array $config name-value pairs that will be used to initialize the object properties
	 */
	public function __construct($id, $controller, $actionMethod, $config = array())
	{
		$this->actionMethod = $actionMethod;
		parent::__construct($id, $controller, $config);
	}

Qiang Xue committed
40
	/**
Qiang Xue committed
41 42 43 44
	 * 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).
Qiang Xue committed
45
	 */
Qiang Xue committed
46
	public function runWithParams($params)
Qiang Xue committed
47
	{
Qiang Xue committed
48 49
		$args = $this->controller->bindActionParams($this, $params);
		return (int)call_user_func_array(array($this->controller, $this->actionMethod), $args);
Qiang Xue committed
50 51
	}
}