8

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.

7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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