Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my camel cased actions in Zend MVC attempting to call non-camelcased method names?

The Zend standard for action names is camelCase, yet if I create an action with camel casing, the request fails because it tries to call the method (action) without the camel casing!

Example:

I have an action named "changeEmail" in module "abc". The method is "changeEmailAction" (created by Zend Tool). If I try to access /abc/changeEmail, I get an error returned that says 'Message: Action "changeemail" does not exist and was not trapped in __call()'.

The ONLY way I have been able to make it work is by only creating action names in all lowercase. This makes for terrible readability and is contrary to the suggested naming convention. What am I missing?

like image 918
MikeH Avatar asked Jul 22 '10 22:07

MikeH


2 Answers

The default behavior of a Zend Framework Action Controller/Router is to enforce a URL naming scheme of all lowercase, with dashes separating the words.

http://example.com/controller/my-thing

When this URL is translated into an action name, camel casing is applied.

public function myThingAction()
{
}

If you really really really want URLs that are camel cased, you should look into configuring your application with a custom Zend Router

like image 178
Alan Storm Avatar answered Oct 30 '22 01:10

Alan Storm


I found the answer to this:

In the url, for multi-word action names, you must separate the words with hyphens, i.e.

/abc/change-email

will call the method "changeEmailAction" in the controller.

like image 22
MikeH Avatar answered Oct 30 '22 03:10

MikeH