<p>After crawling the Yii repository issues I found out how to pass and retrieve the arguments.</p>
<p>In case someone else is struggeling with this I'd like to share this little summary:</p>
<pre class="lang-php prettyprint-override"><code># Controller-1
public function actionSomeMethodName()
{
    // call action of controller-2
    Craft::$app-&gt;runAction('mymodule/controller-2/method-other-controller', ['paramsWrapperName' =&gt; ['someKey' =&gt; 'some value'] ]);

    // do something ...
}
</code></pre>
<p>The argument-name <code>$paramsWrapperName</code> has to match the <em>outter-array-index</em> where you make the call and you have to <em>type-cast</em> the argument as <code>array</code> otherwise you get a baaaaaad baad exception</p>
<pre class="lang-php prettyprint-override"><code># Controller-2
public function actionMethodOtherController(array $paramsWrapperName)
{
    // do something with $paramsWrapperName
}
</code></pre>
<p>Of course instead of <em>paramsWrapperName</em> a simple <em>params</em> or simular makes more sense, just wanted to make it clearer that way..</p>

CC BY-SA 4.0
2023-03-12T16:06:25.643Z
2023-03-12T16:06:25.643Z
Luckyfella
<p>new to CraftCMS - I'm building a website that has to handle two different APIs, where the user logs into API-1 and after succeeding the website has to call an other API checking for a status while using data that was returned from the first API.</p>
<p>I started to set-up two controllers to handle the requests of each API separately. What I have to do is to fire an action from controller-1 (login-callback) and if login was ok I would like to directly fire an action from controller-2 handling the second API (without the user having to take action by clicking a button). Some research showed that I can do</p>
<pre class="lang-php prettyprint-override"><code>Craft::$app-&gt;runAction('mymodule/contoller/method-name-call');
</code></pre>
<p>That works so far but I have to pass some data as params and found out that the call then should look like:</p>
<pre class="lang-php prettyprint-override"><code>Craft::$app-&gt;runAction('mymodule/contoller/method-name-call', ['foo' =&gt; 'bar']);
</code></pre>
<p>But I can't manage to access the passed arguments :/
Even tried to pass to pass as a GET-Param like:</p>
<pre class="lang-php prettyprint-override"><code>Craft::$app-&gt;runAction('mymodule/contoller/method-name-call?foo=bar');
</code></pre>
<p>and then access via:</p>
<pre class="lang-php prettyprint-override"><code>$request = Craft::$app-&gt;getRequest();
$data = $request-&gt;get('foo');
</code></pre>
<p>but no success..</p>
<p>Can somebody advice me how to access the passed params in my case?</p>

<modules><params><action>
Call controller from controller passing arguments
# Call controller from controller passing arguments

(Asked by: username_0 on 2023-03-10)

new to CraftCMS - I'm building a website that has to handle two different APIs, where the user logs into API-1 and after succeeding the website has to call an other API checking for a status while using data that was returned from the first API.
I started to set-up two controllers to handle the requests of each API separately. What I have to do is to fire an action from controller-1 (login-callback) and if login was ok I would like to directly fire an action from controller-2 handling the second API (without the user having to take action by clicking a button). Some research showed that I can do
Craft::$app->runAction('mymodule/contoller/method-name-call');

That works so far but I have to pass some data as params and found out that the call then should look like:
Craft::$app->runAction('mymodule/contoller/method-name-call', ['foo' => 'bar']);

But I can't manage to access the passed arguments :/
Even tried to pass to pass as a GET-Param like:
Craft::$app->runAction('mymodule/contoller/method-name-call?foo=bar');

and then access via:
$request = Craft::$app->getRequest();
$data = $request->get('foo');

but no success..
Can somebody advice me how to access the passed params in my case?

**Tags:** modules, params, action

---

## 1 answers

### Answer by username_0 on 2023-03-12. Score: 2 | Accepted answer

After crawling the Yii repository issues I found out how to pass and retrieve the arguments.
In case someone else is struggeling with this I'd like to share this little summary:
# Controller-1
public function actionSomeMethodName()
{
    // call action of controller-2
    Craft::$app->runAction('mymodule/controller-2/method-other-controller', ['paramsWrapperName' => ['someKey' => 'some value'] ]);

    // do something ...
}

The argument-name $paramsWrapperName has to match the outter-array-index where you make the call and you have to type-cast the argument as array otherwise you get a baaaaaad baad exception
# Controller-2
public function actionMethodOtherController(array $paramsWrapperName)
{
    // do something with $paramsWrapperName
}

Of course instead of paramsWrapperName a simple params or simular makes more sense, just wanted to make it clearer that way..


---

