1

So I am working on it first time. I created a Controller DB_DuhController having a method actionFoo()

I am then calling it as http://domain.craft.dev/admin/DB/duh/Foo but it's giving 404 all the time. What is wrong being done by me?

  • Should it be /admin/db/duh/foo with lower case db? I think the plugin name is lowercase for first letter: buildwithcraft.com/docs/plugins/… same with action name foo not Foo. Also assume you have a CP route in place for the /admin request. – Luke Holder Oct 20 '15 at 9:39
  • /admin is working but not after that. – Volatil3 Oct 20 '15 at 10:25
  • post your cp route. – Luke Holder Oct 20 '15 at 10:27
  • My hookRegisterCpRoutes method is empty. Do I need to define routes first? – Volatil3 Oct 20 '15 at 10:27
  • Yes unless you are accessing it with the /actions url – Luke Holder Oct 20 '15 at 10:29
2

You need to use /actions (or whatever your Trigger word is) to access Controller actions.

Documentation: http://buildwithcraft.com/docs/config-settings#actionTrigger

EDIT: I realize I wasn't clear enough; this variable defaults to /actions. Unless you've set it to something else in your Config, add the /actions to your URL to access the Controller action.

So, your URL would be this: http://domain.craft.dev/actions/PluginHandle/Duh/foo

Note that capitalization matters.

It's also important to make sure that if you plan on making calls to this URL from outside Craft, you'll need to make sure that you're allowing anonymous access by setting that variable at the top of your controller:

protected $allowAnonymous = true;

  • My Config does not have any such entry. – Volatil3 Oct 20 '15 at 17:14
  • the default action trigger is 'actions' so there doesn't need to be anything in your config. just try hitting /actions/db/dauh/foo – Luke Holder Oct 21 '15 at 6:57

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.