Non-CP routes in plugins I'm building a custom plugin and need to have a publicly accessible (non-CP) route as part of the plugin.

From what I've read I can use registerSiteRoutes() to register non-CP routes within my plugin. However, I'm getting a 404 when I do this. Here's my setup.

MyPlugin.php  

&lt;?php
namespace Craft;

  class MyPlugin extends BasePlugin {

    ...

    public function registerSiteRoutes() {
      return array(
        'myroute'           =&gt; array('action' =&gt; 'myplugin/access/index')
      );
    }
  }


MyPlugin_AccessController.php  

&lt;?php
namespace Craft;

class Portal_AccessController extends BaseController {

  protected $allowAnonymous = true;

  public function index() {

    $templatesPath = craft()-&gt;path-&gt;pluginsPath().'myplugin/templates/site/';
    craft()-&gt;path-&gt;setTemplatesPath($templatesPath);

    $this-&gt;renderTemplate('index');

  }

}


I have setup a basic template at /plugins/myplugin/templates/site/index.html

Hitting mydomain.com/myplugin results in a 404. Am I thinking of this correctly? Is it possible to have a non-CP route that points to a controller method in my plugin?
There are a couple of issues here:


Any action methods in the controller class needs the "action" prefix to their name, i.e. actionIndex() for your "index" action, or actionLogin() for another action route calling "myPlugin/access/login".


In other words, rename your index() method in the controller to actionIndex(), and it should work.


For action routes, plugin handles should be written in camelcase – i.e. "myPlugin/access/index", not "myplugin/access/index".
You have a minor typo in the controller:

$templatesPath = craft()->path->pluginsPath().'myplugin/templates/site/';


should read

$templatesPath = craft()-&gt;path-&gt;getPluginsPath().'myplugin/templates/site/';


Addendum: this might just be a typo in the question text, but your controller class is actually named "Portal_AccessController", so it will obviously not respond to the route "myPlugin/access/index" – the latter should read "portal/access/index" (or the controller should be renamed "MyPlugin_AccessController)