runAction() public method

If the action ID is empty, the method will use [[defaultAction]].
See also: createAction
public runAction ( string $id, array $params = [] ) : integer
$id string the ID of the action to be executed.
$params array the parameters (name-value pairs) to be passed to the action.
return integer the status of the action execution. 0 means normal, other values mean abnormal.
 /**
  * Extending runAction to handle extra params loaded dynamically
  * by (task) commands requirements or defined in the build script
  *
  * @inheritdoc
  */
 public function runAction($id, $params = [])
 {
     Log::logger()->addDebug('Executing application command {controller}/{action}', ['controller' => $this->id, 'action' => !empty($id) ? $id : $this->defaultAction]);
     if (!empty($params)) {
         $options = $this->options($id);
         foreach ($params as $name => $value) {
             if (!is_int($name)) {
                 if ($value !== '') {
                     if (!isset($this->_providedOptions[$name])) {
                         $this->_providedOptions[$name] = 1;
                     } else {
                         $this->_providedOptions[$name]++;
                     }
                 }
                 if (!in_array($name, $options, true)) {
                     if ($value !== '') {
                         $this->extraParams[$name] = $value;
                     }
                     unset($params[$name]);
                 }
             }
         }
     }
     parent::runAction($id, $params);
 }
Example #2
0
 public function runAction($id, $params = [])
 {
     // Create attributes for all options available for the given API method.
     $options = $this->options($id === '' ? $this->defaultAction : $id);
     foreach ($options as $option) {
         $this->{$option} = '';
     }
     return parent::runAction($id, $params);
 }
 /**
  * Runs an action within this controller with the specified action ID and parameters.
  */
 public function runAction($id, $params = [])
 {
     if (false === empty($params['id'])) {
         static::$configAlias = $params['id'];
     }
     $this->configName = empty(static::$configAlias) ? '' : static::$configAlias;
     $this->getConfig();
     if (empty(static::$config)) {
         throw new InvalidParamException(\Yii::t('yii', 'Unknown daemon ID!'));
     }
     $this->reloadComponent();
     return parent::runAction($id, $params);
 }