开发者

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开发者_如何学C?


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


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.


You should use hyphen-seperated names in your URLs, e.g. /abc/change-email.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜