InlineAction.php 1.5 KB
Newer Older
Qiang Xue committed
1 2 3
<?php
/**
 * @link http://www.yiiframework.com/
Qiang Xue committed
4
 * @copyright Copyright (c) 2008 Yii Software LLC
Qiang Xue committed
5 6 7
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
8
namespace yii\base;
Qiang Xue committed
9 10

/**
Qiang Xue committed
11
 * InlineAction represents an action that is defined as a controller method.
Qiang Xue committed
12
 *
Qiang Xue committed
13 14
 * The name of the controller method is available via [[actionMethod]] which
 * is set by the [[controller]] who creates this action.
Qiang Xue committed
15 16
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
17
 * @since 2.0
Qiang Xue committed
18
 */
Qiang Xue committed
19
class InlineAction extends Action
Qiang Xue committed
20
{
Qiang Xue committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	/**
	 * @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
38
	/**
Qiang Xue committed
39 40 41 42
	 * 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
43
	 */
Qiang Xue committed
44
	public function runWithParams($params)
Qiang Xue committed
45
	{
Qiang Xue committed
46 47
		$args = $this->controller->bindActionParams($this, $params);
		return (int)call_user_func_array(array($this->controller, $this->actionMethod), $args);
Qiang Xue committed
48 49
	}
}