Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting routes in application.ini in Zend Framework

I'm a Zend Framework newbie, and I'm trying to work out how to add another route to my application.ini file.

I currently have my routes set up as follows:

resources.router.routes.artists.route = /artists/:stub
resources.router.routes.artists.defaults.controller = artists
resources.router.routes.artists.defaults.action = display

...so that /artists/joe-bloggs uses the "display" action of the "artists" controller to dipslay the profile the artist in question - that works fine.

What I want to do now is to set up another route so that /artists/joe-bloggs/random-gallery-name goes to the "galleries" action of the "artists" controller.

I tried adding an additional block to the application.ini file (beneath the block above) like so:

resources.router.routes.artists.route = /artists/:stub/:gallery
resources.router.routes.artists.defaults.controller = artists
resources.router.routes.artists.defaults.action = galleries

...but when I do that the page at /artists/joe-bloggs no longer works (Zend tries to route it to the "joe-bloggs" controller).

How do I set up the routes in application.ini so that I can change the action of the "artists" controller depending on whether "/:gallery" exists?

I realise I'm probably making a really stupid mistake, so please point out my stupidity and set me on the right path (no pun intended).

like image 282
Paul Watson Avatar asked Dec 31 '10 16:12

Paul Watson


2 Answers

Try reversing the order of the routes. ZF matches routes in the opposite order they are added (so that the default route is the last to be matched)

If that doesn't work, you'll probably have to investigate regex routes with optional components.

like image 98
Darryl E. Clarke Avatar answered Oct 12 '22 11:10

Darryl E. Clarke


Your second block needs to have a different route name, rename the 'artists' word to something similar to this for your new block:

resources.router.routes.artists-gal.route = /artists/:stub/:gallery
resources.router.routes.artists-gal.defaults.controller = artists
resources.router.routes.artists-gal.defaults.action = galleries
like image 30
mr12086 Avatar answered Oct 12 '22 11:10

mr12086