<p>It sounds like you just want a cron job to trigger an action on your plugin.</p>

<p>You don't need to register any Control Panel routes for that, so you can remove your <code>registerCpRoutes</code> method.</p>

<p>If your plugin only has one controller, the URL your cron job would want to target would be:</p>

<pre><code>yoursite.com/actions/pluginHandle/pluginAction
</code></pre>

<p>You can read more about it in the <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow">plugin controller</a> docs.</p>

CC BY-SA 3.0
2015-11-19T03:33:48.730Z
That worked! Thanks!

In the [plugin controller](http://buildwithcraft.com/docs/plugins/controllers) docs it might be helpful to add a cron link example that shows actions/ in the path because none of the current examples show actions/ in the path (because actions/ is not needed in any of the other examples):
<input type="hidden" name="action" value="cocktailRecipes/ingredients/saveIngredient">
Adam Fairbanks
CC BY-SA 3.0
2015-11-19T03:34:33.883Z
Fair enough... I'll get to that in the morning!
Brad Bell
CC BY-SA 3.0
2015-11-19T03:41:37.483Z
Thanks for the very helpful and responsive support as always!
Adam Fairbanks
CC BY-SA 3.0
2015-11-19T03:56:45.310Z
And maybe also note that camel case is essential for the plugin handle, even though it's all lowercase in other areas.
Adam Fairbanks
CC BY-SA 3.0
2015-11-19T02:31:12.980Z
2015-11-19T02:31:12.980Z
Brad Bell
<p>If the cron jobs are triggered at the server where your Craft installation is hosted, it might be better to implement a <em>consolecommand</em> instead to execute the logic you want. They are well suited for that.</p>

<p>With a console command your crontab entry would look like:</p>

<pre><code>*/1 * * * * php /opt/craft-app/current/craft/app/etc/console/yiic PLUGINNAME ACTIONNAME myParam=myValue
</code></pre>

<p>(where PLUGINNAME is the name of your plugin, and ACTIONNAME is a method defined in your consolecommand; myParam are arguments passed to your action)</p>

<p>An example of a plugin that makes use of a consolecommand: <a href="https://straightupcraft.com/craft-plugins/taskrunner" rel="nofollow noreferrer">https://straightupcraft.com/craft-plugins/taskrunner</a></p>

<p>(beware if you make use of environmental specific variables you might have to do so in your plugin to get the right configuration)</p>

<p>Activation of 'cron actions' through 'url requests' may be considered bad practice;</p>

<ul>
<li>you'd have to open up a section of your admin panel publicly, or implement another authentication mechanism (i.e. api key)</li>
<li>hence, the 'action' may be vulnerable to various kinds of attacks</li>
<li>by activation through cron you can log success and error output more easily to 'cron logs' or get notified by email on failure (through crontab settings)</li>
</ul>

CC BY-SA 3.0
2017-08-09T08:47:46.987Z
2017-08-09T08:47:46.987Z
24HOURSMEDIA
<p>I want to be able to access a plugin page without having to login (for a cron job).</p>

<p>I have added this to the plugin's controller:</p>

<pre><code>protected $allowAnonymous = true;
</code></pre>

<p>However, this url still requires login:</p>

<pre><code>/admin/[plugin]
</code></pre>

<p>(If I login to admin, the above url works.)</p>

<p>If I try the url without <code>/admin</code>:</p>

<pre><code>/[plugin]
</code></pre>

<p>The page doesn't work at all (logged in or not):</p>

<blockquote>
  <p>Page Not Found<br>
  The requested URL was not found on this server.</p>
</blockquote>

<p>How do I make it so I can access my plugin page without login?</p>

<p>BTW, I also have this in the <code>[plugin]Plugin.php</code> file:</p>

<pre><code>public function registerCpRoutes()
{
  return array(
    '[plugin]' =&gt; array('action' =&gt; '[Plugin]/[Action]'),
  );
}
</code></pre>

<plugin-development><plugins><login><authentication><cron>
$allowAnonymous = true - not working
# $allowAnonymous = true - not working

(Asked by: username_0 on 2015-11-19)

I want to be able to access a plugin page without having to login (for a cron job).
I have added this to the plugin's controller:
protected $allowAnonymous = true;

However, this url still requires login:
/admin/[plugin]

(If I login to admin, the above url works.)
If I try the url without /admin:
/[plugin]

The page doesn't work at all (logged in or not):

Page Not Found
  The requested URL was not found on this server.

How do I make it so I can access my plugin page without login?
BTW, I also have this in the [plugin]Plugin.php file:
public function registerCpRoutes()
{
  return array(
    '[plugin]' => array('action' => '[Plugin]/[Action]'),
  );
}

**Tags:** plugin-development, plugins, login, authentication, cron

---

## 2 answers

### Answer by username_1 on 2015-11-19. Score: 2

It sounds like you just want a cron job to trigger an action on your plugin.
You don't need to register any Control Panel routes for that, so you can remove your registerCpRoutes method.
If your plugin only has one controller, the URL your cron job would want to target would be:
yoursite.com/actions/pluginHandle/pluginAction

You can read more about it in the plugin controller docs.

> **Comments:**
> **username_0**: That worked! Thanks!  In the [plugin controller](http://buildwithcraft.com/docs/plugins/controllers) docs it might be helpful to add a cron link example that shows actions/ in the path because none of the current examples show actions/ in the path (because actions/ is not needed in any of the other examples): <input type="hidden" name="action" value="cocktailRecipes/ingredients/saveIngredient">  
> **username_1**: Fair enough... I'll get to that in the morning!  
> **username_0**: Thanks for the very helpful and responsive support as always!  
> **username_0**: And maybe also note that camel case is essential for the plugin handle, even though it's all lowercase in other areas.  

---

### Answer by username_2 on 2017-08-09. Score: 2

If the cron jobs are triggered at the server where your Craft installation is hosted, it might be better to implement a consolecommand instead to execute the logic you want. They are well suited for that.
With a console command your crontab entry would look like:
*/1 * * * * php /opt/craft-app/current/craft/app/etc/console/yiic PLUGINNAME ACTIONNAME myParam=myValue

(where PLUGINNAME is the name of your plugin, and ACTIONNAME is a method defined in your consolecommand; myParam are arguments passed to your action)
An example of a plugin that makes use of a consolecommand: https://straightupcraft.com/craft-plugins/taskrunner
(beware if you make use of environmental specific variables you might have to do so in your plugin to get the right configuration)
Activation of 'cron actions' through 'url requests' may be considered bad practice;

you'd have to open up a section of your admin panel publicly, or implement another authentication mechanism (i.e. api key)
hence, the 'action' may be vulnerable to various kinds of attacks
by activation through cron you can log success and error output more easily to 'cron logs' or get notified by email on failure (through crontab settings)


---

