I'm trying to implement REST and parseExtension
like functionality in my app, running on CakePHP 2.
Instead of having URLs like http://myapp.dev/controller/action.json
I would like to use http://myapp.dev/json/controller/action
.
The reason for this is that sometimes extensions look a little stupid when put onto something like http://myapp.dev/controller/index/show:10/page:2.json
.
While this could be implemented in a custom route, I already have lots of custom routes, and do not want to have to create duplicates of each with a :type
field in there for maintenance reasons.
What would be ideal is setting it up such that any url with /json /xml /html etc. in first place would be treated as if json, xml, html etc. were the extension.
While Prefix Routing looks ideal for this, it requires new methods (e.g. json_index, html_index etc. and I would have to specify each format as a separate prefix).
Is there any good way of doing this? I just want parseExtensions
to instead be like a parsePrefixes
method instead.