5

Recently got tripped up with plugin routing due to casing.

It seems when you're in the control panel, your "plugin handle" is lower-cased in routes, though both seem to work: /cp/settings/plugins/myplugin (/cp/settings/plugins/myPlugin` also works)

However, when using an controller action, it seems like it must be camel cased (/actions/myPlugin/foo).

Seems inconsistent, unless I'm missing some reasoning.

The docs say [PluginHandle]/[ControllerName]/[ActionName], but it seems like it's actually [pluginHandle]/[controllerName]/[actionName] as the example shows (cocktailRecipes/ingredients/saveIngredient).

3

This is the general rule of thumb...

  • Lower (myplugin) - When creating links for the browser to follow ("href" & "src")
  • Camel (myPlugin) - When creating a path for PHP to interpret (like calling an action)
  • Pascal (MyPlugin) - Almost never. Only for naming plugin components. (ie: MyPluginService)

Here's the logic behind lower vs. camel... If it's an "href" or "src" for your browser to follow, you're basically referring to the folder name which contains your plugin. If it's a reference for PHP to interpret, that information is used to trigger a part of your plugin by class name.

In the case of a controller action (/actions/myPlugin/foo), that path starts as a normal browser path, until actions gets interpreted by your root index.php file. Once the index file parses out the actionTrigger, the rest of the path is handled via PHP.

| improve this answer | |
  • 1
    That makes sense. It still feels a little funny to me that it is case insensitive one way (template/cp routing) and not the other way (controller action). – Tim Kelty Jun 25 '14 at 16:52
  • I agree, it took me a little while to wrap my head around. Ultimately, the case-insensitivity is just due to server behavior... nothing that Craft can really even do about it. Despite the case-insensitivity, I use lowercase because you're referring to the folder itself (which is lowercase). – Lindsey D Jun 25 '14 at 16:56

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.