CInlineAction.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * CInlineAction class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CInlineAction represents an action that is defined as a controller method.
  12. *
  13. * The method name is like 'actionXYZ' where 'XYZ' stands for the action name.
  14. *
  15. * @author Qiang Xue <qiang.xue@gmail.com>
  16. * @package system.web.actions
  17. * @since 1.0
  18. */
  19. class CInlineAction extends CAction
  20. {
  21. /**
  22. * Runs the action.
  23. * The action method defined in the controller is invoked.
  24. * This method is required by {@link CAction}.
  25. */
  26. public function run()
  27. {
  28. $method='action'.$this->getId();
  29. $this->getController()->$method();
  30. }
  31. /**
  32. * Runs the action with the supplied request parameters.
  33. * This method is internally called by {@link CController::runAction()}.
  34. * @param array $params the request parameters (name=>value)
  35. * @return boolean whether the request parameters are valid
  36. * @since 1.1.7
  37. */
  38. public function runWithParams($params)
  39. {
  40. $methodName='action'.$this->getId();
  41. $controller=$this->getController();
  42. $method=new ReflectionMethod($controller, $methodName);
  43. if($method->getNumberOfParameters()>0)
  44. return $this->runWithParamsInternal($controller, $method, $params);
  45. $controller->$methodName();
  46. return true;
  47. }
  48. }