Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-30T10:04:24.293Z
Answers.LastActivityDate: 2014-06-30T10:04:24.293Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-30T10:00:05.857Z
Answers.LastActivityDate: 2014-06-30T10:00:05.857Z
Answers.UserDisplayName: Ben Croker
Body: <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>
  
Tags: <config><controller>
Title: Direct access to controller
ThreadText: # 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](http://buildwithcraft.com/docs/plugins/controllers#how-controller-actions-fit-into-routing), 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](http://buildwithcraft.com/docs/plugins/hooks-reference#registerCpRoutes) or [site-facing](http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes)) 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](http://buildwithcraft.com/docs/plugins/controllers#linking-directly-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](http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions) to your controller action so it can be reached by the cron job.
  
  
  ---
  
  