Prechádzať zdrojové kódy

add runWithParams to Action

alexlcdee 8 rokov pred
rodič
commit
7635ec8a7e
1 zmenil súbory, kde vykonal 29 pridanie a 0 odobranie
  1. 29 0
      src/web/Action.php

+ 29 - 0
src/web/Action.php

@@ -6,6 +6,34 @@ use yiins\Yii;
 
 class Action extends \CAction
 {
+    /**
+     * Runs the action with the supplied request parameters.
+     * This method is internally called by {@link CController::runAction()}.
+     * @param array $params the request parameters (name=>value)
+     * @return boolean whether the request parameters are valid
+     * @since 1.1.7
+     */
+    public function runWithParams($params)
+    {
+        $method = new \ReflectionMethod($this, 'run');
+        if ($method->getNumberOfParameters() > 0) {
+            return $this->runWithParamsInternal($this, $method, $params);
+        }
+
+        Yii::web()->response->result = $this->run();
+
+        return true;
+    }
+
+    /**
+     * Executes a method of an object with the supplied named parameters.
+     * This method is internally used.
+     * @param mixed $object the object whose method is to be executed
+     * @param ReflectionMethod $method the method reflection
+     * @param array $params the named parameters
+     * @return boolean whether the named parameters are valid
+     * @since 1.1.7
+     */
     protected function runWithParamsInternal($object, $method, $params)
     {
         $ps = array();
@@ -26,6 +54,7 @@ class Action extends \CAction
             }
         }
         Yii::web()->response->result = $method->invokeArgs($object, $ps);
+
         return true;
     }
 }