mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-14 12:06:54 +01:00
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* CInlineAction class file.
|
|
*
|
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
* @link http://www.yiiframework.com/
|
|
* @copyright Copyright © 2008-2011 Yii Software LLC
|
|
* @license http://www.yiiframework.com/license/
|
|
*/
|
|
|
|
|
|
/**
|
|
* CInlineAction represents an action that is defined as a controller method.
|
|
*
|
|
* The method name is like 'actionXYZ' where 'XYZ' stands for the action name.
|
|
*
|
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
* @version $Id$
|
|
* @package system.web.actions
|
|
* @since 1.0
|
|
*/
|
|
class CInlineAction extends CAction
|
|
{
|
|
/**
|
|
* Runs the action.
|
|
* The action method defined in the controller is invoked.
|
|
* This method is required by {@link CAction}.
|
|
*/
|
|
public function run()
|
|
{
|
|
$controller=$this->getController();
|
|
$methodName='action'.$this->getId();
|
|
$method=new ReflectionMethod($controller,$methodName);
|
|
if(($n=$method->getNumberOfParameters())>0)
|
|
{
|
|
$params=array();
|
|
foreach($method->getParameters() as $i=>$param)
|
|
{
|
|
$name=$param->getName();
|
|
if(isset($_GET[$name]))
|
|
{
|
|
if($param->isArray())
|
|
$params[]=is_array($_GET[$name]) ? $_GET[$name] : array($_GET[$name]);
|
|
else if(!is_array($_GET[$name]))
|
|
$params[]=$_GET[$name];
|
|
else
|
|
throw new CHttpException(400,Yii::t('yii','Your request is invalid.'));
|
|
}
|
|
else if($param->isDefaultValueAvailable())
|
|
$params[]=$param->getDefaultValue();
|
|
else
|
|
throw new CHttpException(400,Yii::t('yii','Your request is invalid.'));
|
|
}
|
|
$method->invokeArgs($controller,$params);
|
|
}
|
|
else
|
|
$controller->$methodName();
|
|
}
|
|
}
|