<p>As <a href="http://buildwithcraft.com/docs/plugins/controllers#how-controller-actions-fit-into-routing" rel="nofollow">that page in the docs says</a>, dedicated controller action URLs will look like:</p>

<pre><code>http://example.com/actions/pluginHandle/actionName
</code></pre>

<p>If your plugin’s name is “CocktailRecipes”, and you have a controller located at plugins/cocktailrecipes/controllers/CocktailRecipesController.php, and within that you have a function called <code>actionSaveIngredient()</code>, you would get to that via:</p>

<pre><code>http://example.com/actions/cocktailRecipes/saveIngredient
</code></pre>

<p>If your controller is actually called CocktailRecipes_IngredientsController.php, it would be this instead:</p>

<pre><code>http://example.com/actions/cocktailRecipes/ingredients/saveIngredient
</code></pre>

<p>Your plugin can also register a route (either <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#registerCpRoutes" rel="nofollow">CP-facing</a> or <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes" rel="nofollow">site-facing</a>) which could provide a cleaner endpoint for the controller:</p>

<pre><code>public function registerSiteRoutes()
{
    return array(
        'saveIngredient' =&gt; array('action' =&gt; 'cocktailRecipes/ingredients/saveIngredient'),
    );
}
</code></pre>

<p>If you had that in place, you’d be able to access CocktailRecipes_IngredientsController’s actionSaveIngredients() like this instead:</p>

<pre><code>http://example.com/saveIngredient
</code></pre>

<p><strong>Note:</strong> I don’t recommend trying to create a route for your controller until you’ve figured out how to get a basic action URL to point to it correctly. No need to add another step of complexity while you’re still troubleshooting.</p>

CC BY-SA 3.0
2014-06-30T10:04:24.293Z
2014-06-30T10:04:24.293Z
Brandon Kelly
<p>The docs explain how to <a href="http://buildwithcraft.com/docs/plugins/controllers#linking-directly-to-controller-actions" rel="nofollow">generate links to controller actions</a>. Assuming your action trigger is "actions" (as it is by default) then your URL will look as follows:</p>

<pre><code>http://www.domain.com/actions/pluginName/controllerName/actionName
</code></pre>

<p>Following the first example in the docs, the URL will look as follows:</p>

<pre><code>http://www.domain.com/actions/cocktailRecipes/ingredients/deleteIngredient
</code></pre>

<p>Be sure to <a href="http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions" rel="nofollow">allow anonymous access</a> to your controller action so it can be reached by the cron job.</p>

CC BY-SA 3.0
2014-06-30T10:00:05.857Z
2014-06-30T10:00:05.857Z
Ben Croker
<p>I'm trying to create a plugin with a controller, but I don't want to render any view but run a script from a cronjob. I can't get into the controller with an url and I'm not sure why. </p>

<p>I already tried everything <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow noreferrer">here</a> but it does not state any way to directly call a controller with an url. Is this possible? </p>

<config><controller>
Direct access to controller
# Direct access to controller

(Asked by: username_0 on 2014-06-30)

I'm trying to create a plugin with a controller, but I don't want to render any view but run a script from a cronjob. I can't get into the controller with an url and I'm not sure why.

I already tried everything [here](http://buildwithcraft.com/docs/plugins/controllers) but it does not state any way to directly call a controller with an url. Is this possible?

**Tags:** config, controller


---

## 2 answers

### Answer by username_1 on 2014-06-30. Score: 4 | Accepted answer

As that page in the docs says, dedicated controller action URLs will look like:
http://example.com/actions/pluginHandle/actionName

If your plugin’s name is “CocktailRecipes”, and you have a controller located at plugins/cocktailrecipes/controllers/CocktailRecipesController.php, and within that you have a function called actionSaveIngredient(), you would get to that via:
http://example.com/actions/cocktailRecipes/saveIngredient

If your controller is actually called CocktailRecipes_IngredientsController.php, it would be this instead:
http://example.com/actions/cocktailRecipes/ingredients/saveIngredient

Your plugin can also register a route (either CP-facing or site-facing) which could provide a cleaner endpoint for the controller:
public function registerSiteRoutes()
{
    return array(
        'saveIngredient' => array('action' => 'cocktailRecipes/ingredients/saveIngredient'),
    );
}

If you had that in place, you’d be able to access CocktailRecipes_IngredientsController’s actionSaveIngredients() like this instead:
http://example.com/saveIngredient

Note: I don’t recommend trying to create a route for your controller until you’ve figured out how to get a basic action URL to point to it correctly. No need to add another step of complexity while you’re still troubleshooting.


---

### Answer by username_2 on 2014-06-30. Score: 4

The docs explain how to generate links to controller actions. Assuming your action trigger is "actions" (as it is by default) then your URL will look as follows:
http://www.domain.com/actions/pluginName/controllerName/actionName

Following the first example in the docs, the URL will look as follows:
http://www.domain.com/actions/cocktailRecipes/ingredients/deleteIngredient

Be sure to allow anonymous access to your controller action so it can be reached by the cron job.


---

