<p>To quote @Brandon from <a href="https://plus.google.com/116110705947365375372/posts/awJsEZKn2kn">here</a>:</p>

<blockquote>
  <p>Yep you just need to include a $variables argument in your controller
  function, typeset to an array:</p>

<pre><code>public function actionArchive(array $variables = array())
{
    $variables['year'] ...
}
</code></pre>
</blockquote>

CC BY-SA 3.0
2018-02-16T09:35:01.367Z
Gosh, why not write this in the docs? Craft is a bucket of unobvious solutions...
Stalinko
CC BY-SA 3.0
2018-02-16T14:02:56.483Z
@Stalinko haha! That is fair. Craft 3 is much nicer though ;)
Brandon Kelly
CC BY-SA 3.0
2014-06-17T08:20:08.840Z
2014-06-17T08:20:08.840Z
Andris Sevcenko
<p>I'm writing a plugin that uses the registerSiteRoutes hook to create some new routes, and passes those routes to some controllers. In these routes, I have a few pieces of the URL that I'm capturing as named subpatterns. I'm curious how I handle these named variables in the controller that receives them.</p>

<plugin-development><routes><controller><hook>
How do I handle named route variables passed to a controller?
# How do I handle named route variables passed to a controller?

(Asked by: username_0 on 2014-06-17)

I'm writing a plugin that uses the registerSiteRoutes hook to create some new routes, and passes those routes to some controllers. In these routes, I have a few pieces of the URL that I'm capturing as named subpatterns. I'm curious how I handle these named variables in the controller that receives them.

**Tags:** plugin-development, routes, controller, hook


---

## 1 answers

### Answer by username_1 on 2014-06-17. Score: 7 | Accepted answer

To quote @Brandon from here:

Yep you just need to include a $variables argument in your controller
  function, typeset to an array:
public function actionArchive(array $variables = array())
{
    $variables['year'] ...
}

> **Comments:**
> **username_2**: Gosh, why not write this in the docs? Craft is a bucket of unobvious solutions...  
> **username_3**: @username_2 haha! That is fair. Craft 3 is much nicer though ;)  

---

