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.

1 Answer 1


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'] ...
  • Gosh, why not write this in the docs? Craft is a bucket of unobvious solutions...
    – Stalinko
    Commented Feb 16, 2018 at 9:35
  • @Stalinko haha! That is fair. Craft 3 is much nicer though ;) Commented Feb 16, 2018 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.