Answers.Body: <p>Yes it’s possible. First you will need to update your route key so that you’re capturing the <code>name</code> parameter with a valid <a href="http://php.net/manual/en/regexp.reference.subpatterns.php" rel="nofollow">named subpattern</a>. (You were close, but missing the actual <em>pattern</em> part of it).</p>
  
  <pre><code>return array(
      'api/test/(?P&lt;name&gt;[^\/]+)' =&gt; ['action' =&gt; 'api/element/section'],
  );
  </code></pre>
  
  <p>Any named subpattern matches in your route will be passed to your controller action’s <code>$variables</code> argument, if it has one.</p>
  
  <pre><code>class Api_ElementController extends BaseController
  {
      // ...
  
      public function actionSection(array $variables = array())
      {
          $name = $variables['name'];
  
          // ...
      }
  }
  </code></pre>
  
  <p>Note that you specifically need to call the argument “<code>$variables</code>”, and you need to typeset it to an <code>array</code> for this to work.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T20:24:11.173Z
Answers.Text: Does it look to you like I'm doing something wrong with the regex to get the name? Right now I'm not getting to the actionSection method. I put a commented out version of the original in my question.
Answers.UserDisplayName: Tyler Willingham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T20:32:44.357Z
Answers.Text: I’m not sure what that means - is the code above your route or not?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T20:38:12.523Z
Answers.Text: Before implementing your change, hitting /actions/api/element/section/name/triviaQuestions/ will trigger actionSection($name) with $name='triviaQuestions'.   However if I use the above route (/api/test/triviaQuestions) I get a 404 - leading me to believe I've done something wrong in my routing.
Answers.UserDisplayName: Tyler Willingham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T21:18:06.587Z
Answers.Text: @TylerWillingham Ah, there is a bug in your route. Just updated my answer.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-11T19:59:15.373Z
Answers.LastActivityDate: 2014-07-11T21:17:56.210Z
Answers.LastEditDate: 2014-07-11T21:17:56.210Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>We want to mask specific action routes in our project's routes.php file. Currently what we have looks like this:</p>
  
  <pre><code>return array(
      // /actions/api/element/section/name/{$name}/
      'api/test/(?P&lt;name&gt;)'  =&gt; ['action' =&gt; 'api/element/section'],
  );
  </code></pre>
  
  <p>We would like to pass name into the action array somehow. Is there something documented or undocumented that I'm missing? Or is what I'm attempting not possible at this time?</p>
  
Tags: <plugin-development><routes><routing>
Title: How can I implement advanced action routes (in routes.php)?
ThreadText: # How can I implement advanced action routes (in routes.php)?
  
  (Asked by: username_0 on 2014-07-11)
  
  We want to mask specific action routes in our project's routes.php file. Currently what we have looks like this:
  
  ```
  return array(
      // /actions/api/element/section/name/{$name}/
      'api/test/(?P<name>)'  => ['action' => 'api/element/section'],
  );
  
  ```
  
  We would like to pass name into the action array somehow. Is there something documented or undocumented that I'm missing? Or is what I'm attempting not possible at this time?
  
  **Tags:** plugin-development, routes, routing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-11. Score: 5 | Accepted answer
  
  Yes it’s possible. First you will need to update your route key so that you’re capturing the `name` parameter with a valid [named subpattern](http://php.net/manual/en/regexp.reference.subpatterns.php). (You were close, but missing the actual *pattern* part of it).
  
  ```
  return array(
      'api/test/(?P<name>[^\/]+)' => ['action' => 'api/element/section'],
  );
  
  ```
  
  Any named subpattern matches in your route will be passed to your controller action’s `$variables` argument, if it has one.
  
  ```
  class Api_ElementController extends BaseController
  {
      // ...
  
      public function actionSection(array $variables = array())
      {
          $name = $variables['name'];
  
          // ...
      }
  }
  
  ```
  
  Note that you specifically need to call the argument “`$variables`”, and you need to typeset it to an `array` for this to work.
  
  > **Comments:**
  > **username_0**: Does it look to you like I'm doing something wrong with the regex to get the name? Right now I'm not getting to the actionSection method. I put a commented out version of the original in my question.  
  > **username_1**: I’m not sure what that means - is the code above your route or not?  
  > **username_0**: Before implementing your change, hitting /actions/api/element/section/name/triviaQuestions/ will trigger actionSection($name) with $name='triviaQuestions'.   However if I use the above route (/api/test/triviaQuestions) I get a 404 - leading me to believe I've done something wrong in my routing.  
  > **username_1**: @username_0 Ah, there is a bug in your route. Just updated my answer.  
  
  ---
  
  