2

struggling to decipher how to link a plugins controller to an action route. The docs say to use "https://pluginfactory.io/" to scaffold one, but what it generates is a different structure to what the documentation say to use.

I've got a plugin called Gated Content sitting inside: plugins/gated-content

I've got a controller named and located at:

plugins/gated-content/src/controllers/GatedContent_DataCaptureController.php

with the class name of of GatedContent_DataCaptureController

I've just got an actionIndex method which var dumps and exits.

Which would suggest (according to the docs) that the URL to access this should be:

https://craftcms.localhost/index.php?p=actions/gatedContent/dataCapture/index

But it just throws a 404.

Inside of the .craftplugin file I've also added "controllerName":"GatedContent_DataCaptureController incase, but doesn't seem to make a difference.

What is the correct pattern to use for each of these?

Thanks

2

EDIT: In the first version of the answer I forgot the /admin part of all the example URLs. Added now.

TL;DR version:

To get to the point first before explaining more in-depth: You need to convert the names from camelCase (with capitalisation in the name) to kebab-case (with dashes instead). I would suggest renaming your controller to simply DataCaptureController, since it's within the Gated Content plugin anyways, and you should be able to use:

https://craftcms.localhost/admin/gated-content/data-capture/index

Full answer:

So, the structure is basically plugin-name/controller-name/method-name, all in kebab case, meaning that what is someName should be some-name, as not all servers are case sensitive (althouth URLs technically are, if I'm correct). Also, the Controller and action parts of the class/method name is implied, as you've already correctly done, but as far as I know, not adding the plugin name to the front of your controller (I have not checked this specifically).

So in your case it should be something like this:

https://craftcms.localhost/admin/index.php?p=actions/gated-content/gated-content_data-capture/index

I am honestly not quite sure how underscores are treated in kebab-case, so it could be that this is the correct form:

https://craftcms.localhost/admin/index.php?p=actions/gated-content/gated-content-data-capture/index

Also, you should be able to use the url like this:

https://craftcms.localhost/admin/gated-content/gated-content-data-capture/index

(Or, if you really prefer for some reason, with /actions in the URL:)

https://craftcms.localhost/admin/actions/gated-content/gated-content-data-capture/index

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.