2

I'm trying to create a very simple controller from a "foo plugin", but it seems there is something i did not understand because i can't make it work. (404 error) I looked at contactForm plugin as an example; except i'm trying to respond to a "GET" http request.

My plugin is enable and OK. My plugin is "foo". Here is my controller, in plugins/foo/controllers :

<?php
namespace Craft;

/**
 * Contact Form controller
 */
class fooController extends BaseController {

  function actionHello() {
     $this->renderTemplate('foo/test');
  }

}
?>

This is not supposed to be called with this uri ?

http://craft.local/index.php?p=actions/foo/Hello

Must i register a route to make this work ?

Also tried renaming my controller and class to "foo_testController", and then calling :

http://craft.local/index.php?p=actions/foo/test/Hello

without success.

What am i missing ?

  • No harm in editing your own question if you don't have the rep to answer it properly... However, once you do have enough rep points, I'd suggest moving that to a real answer to improve clarity for future readers. – Lindsey D Jun 29 '14 at 20:06
  • okay thanks for your help; i just created a real answer – yann_yinn Jun 30 '14 at 7:33
3

I solved the problem using Pascal Case for naming all my files and classes. I was using camel Case...

So all works fine with those filenames for my "foo" plugin :

  • FooPlugin.php

  • controllers/FooController.php

I used Pascal Case for the classes name too, mainly for consistency reason; but i noticed that :

  • using camelCase for controller class name if the filename is in PascalCase does not break anything

  • using camelCase for plugin classname breaks the controller.

Anyway, if you don't want issues, juste use Pascal Case (file names and class names) everywhere and you should be Ok.

Please note that with apache, this path is calling my controller correctly (all in lower case)

actions/foo/hello
1

Typo:

Depending on your plugin-handle you may have a typo in your action routes. It's important to note that this routes are 'Camel' case-sensitive. Read this answer by Lindsey for more info.

Access:

You need to add your action to $allowAnonymous, otherwise only users who are logged in can access the controller:

protected $allowAnonymous = array('actionHello');
  • Thanks for your anwser. My plugin directory is "foo", my controller is "controllers/fooController.php" and inside, my action is "actionHello", so from what i read, my path should be "actions/foo/Hello" . Tried others combinations and playing with case with no success. Surely i missed something stupid in my way ... Also added $allowAnonymous array just in case, but i'm logged in for my tests. – yann_yinn Jun 29 '14 at 13:14
  • 1
    Ok, solved, I added my answer at the top of my question. – yann_yinn Jun 29 '14 at 13:48

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.