Qiang Xue
13 years ago
3 changed files with 86 additions and 120 deletions
@ -1,53 +1,50 @@ |
|||||||
<?php |
<?php |
||||||
/** |
/** |
||||||
* CInlineAction class file. |
* InlineAction class file. |
||||||
* |
* |
||||||
* @author Qiang Xue <qiang.xue@gmail.com> |
|
||||||
* @link http://www.yiiframework.com/ |
* @link http://www.yiiframework.com/ |
||||||
* @copyright Copyright © 2008-2011 Yii Software LLC |
* @copyright Copyright © 2008-2012 Yii Software LLC |
||||||
* @license http://www.yiiframework.com/license/ |
* @license http://www.yiiframework.com/license/ |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
namespace yii\base; |
||||||
|
|
||||||
/** |
/** |
||||||
* CInlineAction represents an action that is defined as a controller method. |
* InlineAction represents an action that is defined as a controller method. |
||||||
* |
* |
||||||
* The method name is like 'actionXYZ' where 'XYZ' stands for the action name. |
* The method name is like 'actionXYZ' where 'XYZ' stands for the action name. |
||||||
* |
* |
||||||
* @author Qiang Xue <qiang.xue@gmail.com> |
* @author Qiang Xue <qiang.xue@gmail.com> |
||||||
* @version $Id$ |
* @since 2.0 |
||||||
* @package system.web.actions |
|
||||||
* @since 1.0 |
|
||||||
*/ |
*/ |
||||||
class CInlineAction extends CAction |
class InlineAction extends Action |
||||||
{ |
{ |
||||||
/** |
/** |
||||||
* Runs the action. |
* Runs the action. |
||||||
* The action method defined in the controller is invoked. |
* This method is invoked by the controller to run the action. |
||||||
* This method is required by {@link CAction}. |
* @param array $params the input parameters |
||||||
*/ |
*/ |
||||||
public function run() |
public function run($params) |
||||||
{ |
{ |
||||||
$method='action'.$this->getId(); |
call_user_func_array(array($this->controller, 'action' . $this->id), $params); |
||||||
$this->getController()->$method(); |
|
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Runs the action with the supplied request parameters. |
* Extracts the input parameters according to the signature of the controller action method. |
||||||
* This method is internally called by {@link CController::runAction()}. |
* This method is invoked by controller when it attempts to run the action |
||||||
* @param array $params the request parameters (name=>value) |
* with the user supplied parameters. |
||||||
* @return boolean whether the request parameters are valid |
* @param array $params the parameters in name-value pairs |
||||||
* @since 1.1.7 |
* @return array|boolean the extracted parameters in the order as declared in the controller action method. |
||||||
|
* False is returned if the input parameters do not follow the method declaration. |
||||||
*/ |
*/ |
||||||
public function runWithParams($params) |
public function normalizeParams($params) |
||||||
{ |
{ |
||||||
$methodName='action'.$this->getId(); |
$method = new \ReflectionMethod($this->controller, 'action' . $this->id); |
||||||
$controller=$this->getController(); |
$params = $this->normalizeParams($method, $params); |
||||||
$method=new ReflectionMethod($controller, $methodName); |
if ($params !== false) { |
||||||
if($method->getNumberOfParameters()>0) |
return array($params); |
||||||
return $this->runWithParamsInternal($controller, $method, $params); |
} else { |
||||||
else |
return false; |
||||||
return $controller->$methodName(); |
} |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue