<p>There are a couple of issues here:</p>

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

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

<ol start="2">
<li><p>For action routes, plugin handles should be written in camelcase – i.e. "<strong>myPlugin</strong>/access/index", not "<strong>myplugin</strong>/access/index".</p></li>
<li><p>You have a minor typo in the controller:</p>

<p>$templatesPath = craft()->path-><strong>pluginsPath()</strong>.'myplugin/templates/site/';</p></li>
</ol>

<p>should read</p>

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

<p><em>Addendum: this might just be a typo in the question text, but your controller class is actually named</em> "Portal_AccessController"<em>, 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)</em></p>

CC BY-SA 3.0
2015-10-20T16:23:25.967Z
Not sure why this thing not working for me and keeps giving `Unable to resolve the request`
Volatil3
CC BY-SA 3.0
2015-03-07T08:59:05.380Z
2015-03-07T09:12:12.323Z
2015-03-07T09:12:12.323Z
Mats Mikkel Rummelhoff
<p>I'm building a custom plugin and need to have a publicly accessible (non-CP) route as part of the plugin.</p>

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

<p><strong>MyPlugin.php</strong>  </p>

<pre><code>&lt;?php
namespace Craft;

  class MyPlugin extends BasePlugin {

    ...

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

<p><strong>MyPlugin_AccessController.php</strong>  </p>

<pre><code>&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');

  }

}
</code></pre>

<p>I have setup a basic template at <code>/plugins/myplugin/templates/site/index.html</code></p>

<p>Hitting <code>mydomain.com/myplugin</code> 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?</p>

<plugin-development><routes>
Non-CP routes in plugins
# Non-CP routes in plugins

(Asked by: username_0 on 2015-03-07)

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 
 array('action' => 'myplugin/access/index')
      );
    }
  }

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

    $this->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?

**Tags:** plugin-development, routes

---

## 1 answers

### Answer by username_1 on 2015-03-07. Score: 6 | Accepted answer

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()->path->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)

> **Comments:**
> **username_2**: Not sure why this thing not working for me and keeps giving `Unable to resolve the request`  

---

