<p>I believe this is caused by not including <code>array</code> in the function parameter, preceding the variable.</p>

<p>Changing to <code>public function actionEdit (array $variables = [ ])</code> should do the trick.</p>

<p>As a bonus - can anyone explain why? Seems like the $variables variable needs to be cast as an array?</p>

CC BY-SA 3.0
2017-01-28T14:29:39.223Z
Yes indeed. Would love to know why!
Fred Carlsen
CC BY-SA 3.0
2017-01-28T14:26:34.530Z
2017-01-28T14:26:34.530Z
crawf
<p>Another option is to retrieve the route variables inside your controller action and not pass anything into the function as a parameter :</p>

<pre><code>public function actionEdit() 
{
    $routeParams = craft()-&gt;urlManager-&gt;getRouteParams();
    $folderId = $routeParams['variables']['folderId'];

    //Do stuff with $folderId

    $this-&gt;renderTemplate('largeupload/LargeUpload_Edit', []);
}
</code></pre>

CC BY-SA 3.0
2017-01-28T20:09:07.260Z
2017-01-28T20:09:07.260Z
Aaron Berkowitz
<p>I'm trying to add some custom routes for my plugin, but it's throwing a 400 CHttpException for <code>invalidActionParams</code> when accessing <code>largeupload/folders/2</code> as an example.</p>

<pre class="lang-php prettyprint-override"><code>public function registerCpRoutes ()
{
return array(
    'largeupload'                           =&gt; array( 'action' =&gt; 'largeUpload/index' ),
    'largeupload/folders'                   =&gt; array( 'action' =&gt; 'largeUpload/folder/index' ),
    'largeupload/folders/new'               =&gt; array( 'action' =&gt; 'largeUpload/folder/edit' ),
    'largeupload/folders/(?P&lt;folderId&gt;\d+)' =&gt; array( 'action' =&gt; 'largeUpload/folder/edit' ),
);
}
</code></pre>

<p>My controller is called <code>LargeUpload_Folder</code>, and my action <code>actionEdit()</code>.</p>

<pre class="lang-php prettyprint-override"><code>public function actionEdit ($variables = [ ])
{
    /* Simplified */
    if ( isset($variables['folderId']) ) {
    }
    else {
    }

    $this-&gt;renderTemplate('largeupload/LargeUpload_Edit', [
    ]);
}
</code></pre>

<p>If I remove <code>$variables = [ ]</code> from the action parameters, it doesn't return an error anymore.</p>

<p>Any ideas?</p>

<plugin-development><routing>
Trouble with registerCpRoutes()
# Trouble with registerCpRoutes()

(Asked by: username_0 on 2017-01-28)

I'm trying to add some custom routes for my plugin, but it's throwing a 400 CHttpException for invalidActionParams when accessing largeupload/folders/2 as an example.
public function registerCpRoutes ()
{
return array(
    'largeupload'                           => array( 'action' => 'largeUpload/index' ),
    'largeupload/folders'                   => array( 'action' => 'largeUpload/folder/index' ),
    'largeupload/folders/new'               => array( 'action' => 'largeUpload/folder/edit' ),
    'largeupload/folders/(?P\d+)' => array( 'action' => 'largeUpload/folder/edit' ),
);
}

My controller is called LargeUpload_Folder, and my action actionEdit().
public function actionEdit ($variables = [ ])
{
    /* Simplified */
    if ( isset($variables['folderId']) ) {
    }
    else {
    }

    $this->renderTemplate('largeupload/LargeUpload_Edit', [
    ]);
}

If I remove $variables = [ ] from the action parameters, it doesn't return an error anymore.
Any ideas?

**Tags:** plugin-development, routing


---

## 2 answers

### Answer by username_1 on 2017-01-28. Score: 2 | Accepted answer

I believe this is caused by not including `array` in the function parameter, preceding the variable.

Changing to `public function actionEdit (array $variables = [ ])` should do the trick.

As a bonus - can anyone explain why? Seems like the $variables variable needs to be cast as an array?

> **Comments:**
> **username_0**: Yes indeed. Would love to know why!  

---

### Answer by username_2 on 2017-01-28. Score: 2

Another option is to retrieve the route variables inside your controller action and not pass anything into the function as a parameter :
public function actionEdit() 
{
    $routeParams = craft()->urlManager->getRouteParams();
    $folderId = $routeParams['variables']['folderId'];

    //Do stuff with $folderId

    $this->renderTemplate('largeupload/LargeUpload_Edit', []);
}


---

