Answers.Body: <p>You want to take a look at the <code>registerSiteRoutes()</code> method in your plugin class. In this example, it will route a request to your <code>MyPluginHandle_FooController::actionBar()</code> method. <code>foo</code> is obviously the name of the controller, and <code>bar</code> is the method.</p>
  
  <pre><code>public function registerSiteRoutes()
  {
      return array(
          'some/route/here' =&gt; array('action' =&gt; 'myPluginHandle/foo/bar'),
      );
  }
  </code></pre>
  
  <p>Here is what the controller would look like with these naming conventions:</p>
  
  <pre><code>&lt;?php
  namespace
  
  class MyPluginHandle_FooController extends BaseController
  {
      // Allow anonymous users (users that aren't logged in) to use this controller
      protected $allowAnonymous = true;
  
      public function actionBar()
      {
          // do something
      }
  }
  </code></pre>
  
  <p>You can also do the same thing for CP routes.</p>
  
  <p><a href="http://buildwithcraft.com/docs/plugins/templates#dynamic-url-routing" rel="nofollow">http://buildwithcraft.com/docs/plugins/templates#dynamic-url-routing</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-15T04:48:13.247Z
Answers.Text: Does action as a suffix actually work or does it need to be a prefix, as in `actionBar()`?
Answers.UserDisplayName: Selvin Ortiz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-15T18:28:00.663Z
Answers.Text: My mistake, you are correct. It's `actionBar`, I had that inverted on accident. I updated my answer.
Answers.UserDisplayName: Justin Kimbrell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-14T17:07:41.510Z
Answers.LastActivityDate: 2015-01-15T18:27:17.293Z
Answers.LastEditDate: 2015-01-15T18:27:17.293Z
Answers.UserDisplayName: Justin Kimbrell
Body: <p>Craft's documentation states: "If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded".  Instead of loading the template, how can I set the route to run an action instead?  In config/routes.php, I set 'entryurl' => array('action' => 'action/path'), but this does not work.</p>
  
Tags: <entry><controller><category>
Title: How do you route an entry or category URI to a plugin controller?
ThreadText: # How do you route an entry or category URI to a plugin controller?
  
  (Asked by: username_0 on 2015-01-13)
  
  Craft's documentation states: "If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded". Instead of loading the template, how can I set the route to run an action instead? In config/routes.php, I set 'entryurl' => array('action' => 'action/path'), but this does not work.
  
  **Tags:** entry, controller, category
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-01-14. Score: 1 | Accepted answer
  
  You want to take a look at the `registerSiteRoutes()` method in your plugin class. In this example, it will route a request to your `MyPluginHandle_FooController::actionBar()` method. `foo` is obviously the name of the controller, and `bar` is the method.
  
  ```
  public function registerSiteRoutes()
  {
      return array(
          'some/route/here' => array('action' => 'myPluginHandle/foo/bar'),
      );
  }
  
  ```
  
  Here is what the controller would look like with these naming conventions:
  
  ```
  <?php
  namespace
  
  class MyPluginHandle_FooController extends BaseController
  {
      // Allow anonymous users (users that aren't logged in) to use this controller
      protected $allowAnonymous = true;
  
      public function actionBar()
      {
          // do something
      }
  }
  
  ```
  
  You can also do the same thing for CP routes.
  
  <http://buildwithcraft.com/docs/plugins/templates#dynamic-url-routing>
  
  > **Comments:**
  > **username_2**: Does action as a suffix actually work or does it need to be a prefix, as in `actionBar()`?  
  > **username_1**: My mistake, you are correct. It's `actionBar`, I had that inverted on accident. I updated my answer.  
  
  ---
  
  