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
<?php
namespace Craft;
class MyPlugin extends BasePlugin {
...
public function registerSiteRoutes() {
return array(
'myroute' => array('action' => 'myplugin/access/index')
);
}
}
MyPlugin_AccessController.php
<?php
namespace Craft;
class Portal_AccessController extends BaseController {
protected $allowAnonymous = true;
public function index() {
$templatesPath = craft()->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?