1
votes

I'm working on a Zend Framework API and need to follow a particular format for URLs, so I was hoping for some help regarding how to configure the routing correctly.

http://example.com/module/controller/method/actionNameHere

The above URL would need to route to the function actionNameHereAction.

Any help is appreciated.

2
Isn't that how ZF rolls, straight out the box? You just need to set your folder structure correctly and name your files and classes correctly?martynthewolf
@Leirith: Well, not exactly. He's got a that /method/ segment in there, not sure what purpose that serves. Looks like custom routes. But, you're right, it's pretty much a standard case, right out of the manual.David Weinraub
And what that part method stands for?Jakub Truneček
method is a static part of the URL, it will be in every request. actionNameHere should be camelCase.Luke Eller

2 Answers

1
votes

The beauty of routing is that it gives you the tools for hiding exactly those pieces of information you are putting into your URL.

Apart from that, as far as I know ZF routes by default so that your URL would end up in ...

  • the action with name method of
  • the controller with name controller of
  • the module with name module

So either your example-URL is complicating things or you are almost there.

B/c actionNameHere would be a paramter you could handle in your action with name "methodAction".

But I think you want your URL to look like:

example.com/module/controller/actionNameHere

1
votes

In order to produce the URLs needed, I ended up creating a custom Dispatcher, as it wasn't in the routing that URLs were being converted from actionNameHere to actionnamehereAction, but in the dispatcher. I extended the standard dispatcher and overrode this behaviour so that the action name in the URL remained case-sensitive.