3

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 but it does not state any way to directly call a controller with an url. Is this possible?

4

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.