Monday, June 6, 2011

Walkthrough on how to use Zend_Controller_Router_Route_Chain

I was a little confused at first look of what Zend_Controller_Router_Route_Chain does so here's my 2 cents on explaining this feature.

I use Zend_Config_Xml so I will write my example as XML.

Say we have a URL like this: http://supercars.com/automobile/make-audi/model-r8/year-2011
that we want to route and we wanted to use the http://supercars.com/automobile as our base url.

Here is what we would do to implement router chaining on the above URL.

<routes>
    <Automobile>
        <type>Zend_Controller_Router_Route</type>
        <route>automobile</route>
        <defaults>
            <controller>automobile</controller>
            <action>index</action>
        </defaults>
        <chains>
            <Make>
                <type>Zend_Controller_Router_Route</type>
                <route>make-:make</route>
                <defaults>
                     <action>make</action>
                </defaults>
                <reqs>
                    <make>[\w]+</make>
                </reqs>
                <chains>
                    <Model>
                        <type>Zend_Controller_Router_Route</type>
                        <route>model-:model</route>
                        <defaults>
                            <action>model</action>
                        </defaults>
                        <reqs>
                            <model>[\w]+</model?
                        </reqs>
                        <chains>
                                <Year>
                                <type>Zend_Controller_Router_Route</type>
                                <route>year-:year</route>
                                <defaults>
                                    <action>year</year>
                                </defaults>
                                <reqs>
                                    <year>[\d]{4}</year>
                                </reqs>
                            </Year>
                        </chains>
                    </Model>
                </chains>
            </Make>
        </chains>
    </Automobile>
</routes>



Assuming we are only going to use controller Automobile.

Route name "Automobile-Make" correspond to URL:
http://supercars.com/automobile/make-Audi

Route name "Automobile-Make-Model" corresponds to URL:
http://supercars.com/automobile/make-Audi/Model-R8

Route name "Automobile-Make-Model-Year" corresponds to URL:
http://supercars.com/automobile/make-Audi/Model-R8/year-2011

You get the groove? Also notice the route tags inside the chains, it is only specific to specific URI for example: "make-:make" instead of rewriting the whole "route" to "automobile/make-:make" which is being appended. Also note that route "Automobile" will not exist here.

Another neat thing is you can create other routes on the same chain level so if you want to do something like: http://supercars.com/automobile/make-Audi/page-8 you declare a route the same as on the route "Model" level as you will see below.

        <chains>
            <Make>
                <type>Zend_Controller_Router_Route</type>
                <route>make-:make</route>
                <defaults>
                     <action>make</action>
                </defaults>
                <reqs>
                    <make>[\w]+</make>
                </reqs>

                <chains>
                    <Page>
                        <type>Zend_Controller_Router_Route</type>
                        <route>page-:page</route>
                        <defaults>
                            <action>page</action>
                        </defaults>
                        <reqs>
                            <make>[\d]+</make>
                        </reqs>

                    </Page>
                    <Model>
                        <type>Zend_Controller_Router_Route</type>
                        <route>model-:model</route>
                        <defaults>
                            <action>model</action>
                        </defaults>
                        <reqs>
                            <model>[\w]+</model?
                        </reqs>

                    </Model>
                </chains>

            <Make>

         </chains>

13 comments:

co wendy said...

Sergei , October 22, 1970 Born in Christian Louboutin Bois Dore Moscow State Ozherelye. Perhaps influenced by Cheap LV Handbags their parents worship warrior army, join the army in cheap jordans 1989, and into the elite airborne military service. 1991, by the influence of the Soviet Union, the uggs on sale Russian christian louboutin army general lack of funds, a large number ugg australia of Air Jordan 11 Gamma Blue soldiers seeking veterans, but under extremely difficult conditions still dedicated, praise superiors, and soon was sent to the famous christian louboutin shoes Ryazan Higher ugg Airborne Command School studies. After graduating in 1994, entered the famous Pskov 76th Guards Airborne discount christian louboutin Division, served as discount nike jordans the reconnaissance platoon, reconnaissance ugg soldes deputy company commander, company commander, battalion airborne regiment scouting director and other duties.From 2000 to Cheap Louis Vuitton Handbags 2004, where the forces have repeatedly ordered war with Chechen militants. Because of their opponents in order to form the squad activity and haunted impermanence, the Russians had to ugg boots mobilize elite troops set up large uggs outlet number of small units, "a Discount Louis Vuitton small wholesale jordan shoes play small" Implementation siege. commanding troops in Chechnya, Christian Louboutin Daffodile Ingushetia and other places over the mountains, to track the militants fled. Discount LV Handbags Although the militants were extremely vigilant, but as long as the task has never had outsmarted.August 8, 2008, Georgia suddenly invade South Ossetia (Russian peacekeepers stationed ugg pas cher there), the Russian military to respond quickly, including including the 76th Guards Airborne Division, more than christian louboutin remise 50% 3,000 people were immediately delivered to the pro-Russian Abkhazia, Georgia cheap nike jordan shoes Army contain two infantry brigades, effectively coordinate the cheap christian louboutin direction of the Russian Bags Louis Vuitton troops in South Ossetia.

Guo Guo said...

yao20150324
michael kors handbags
thomas sabo
valentino shoes
ralph lauren outlet
mac cosmetics
true religion outlet
tods outlet
adidas wings
iphone 6 cases
thomas sabo uk
hollister clothing
ray ban uk
ralph lauren outlet
abercrombie
cheap oakley sunglasses
mont blanc
hollister shirts
burberry outlet online
burberry handbags
replica watches
converse shoes
ghd
tods outlet
toms shoes
lacoste shirts
michael kors outlet online
michael kors handbags
louis vuitton outlet
ferragamo shoes
soccer jerseys
michael kors outlet
ray ban sunglasses

oakleyses said...

tory burch outlet, longchamp outlet, burberry, ray ban sunglasses, tiffany and co, nike outlet, replica watches, louis vuitton, ray ban sunglasses, nike air max, jordan shoes, polo ralph lauren outlet, michael kors outlet, tiffany jewelry, michael kors outlet, christian louboutin outlet, burberry outlet online, michael kors outlet, michael kors, oakley sunglasses, longchamp, prada outlet, prada handbags, cheap oakley sunglasses, oakley sunglasses, oakley sunglasses, ugg boots, louboutin shoes, michael kors outlet, ugg boots, polo ralph lauren outlet, louis vuitton outlet, nike free, chanel handbags, louboutin outlet, louis vuitton outlet, oakley sunglasses, ugg boots, replica watches, michael kors outlet, kate spade outlet, uggs on sale, nike air max, louboutin, louis vuitton, louis vuitton

oakleyses said...

air jordan pas cher, ray ban uk, nike roshe, true religion jeans, air force, abercrombie and fitch, north face, new balance pas cher, sac longchamp, longchamp pas cher, mulberry, oakley pas cher, nike free run uk, coach outlet, nike blazer, hermes, michael kors, nike air max, air max, hollister pas cher, true religion jeans, ralph lauren pas cher, vans pas cher, michael kors, coach outlet, true religion jeans, hollister, michael kors, north face, nike air max, nike roshe run, coach purses, burberry, lululemon, michael kors, lacoste pas cher, hogan, tn pas cher, sac guess, replica handbags, louboutin pas cher, vanessa bruno, timberland, kate spade handbags, converse pas cher, ralph lauren uk, nike free

oakleyses said...

nike roshe, new balance, beats by dre, p90x workout, instyler, valentino shoes, nfl jerseys, babyliss, ghd, hollister, s5 cases, lululemon, soccer shoes, jimmy choo shoes, nike air max, mac cosmetics, giuseppe zanotti, abercrombie and fitch, hollister, herve leger, asics running shoes, nike huarache, celine handbags, louboutin, mont blanc, iphone 6s cases, north face outlet, birkin bag, iphone 5s cases, north face outlet, wedding dresses, mcm handbags, oakley, iphone 6 cases, ralph lauren, longchamp, timberland boots, nike trainers, baseball bats, soccer jerseys, iphone 6s plus cases, insanity workout, iphone 6 plus cases, iphone cases, bottega veneta, chi flat iron, reebok shoes, ipad cases, vans shoes, ferragamo shoes

oakleyses said...

moncler, moncler outlet, marc jacobs, moncler, hollister, montre pas cher, vans, ray ban, replica watches, pandora charms, louis vuitton, supra shoes, sac louis vuitton pas cher, pandora jewelry, swarovski, pandora charms, moncler, bottes ugg, barbour, canada goose, ugg,uggs,uggs canada, louis vuitton, doke gabbana outlet, converse, louis vuitton, lancel, louis vuitton, hollister, moncler, pandora jewelry, doudoune canada goose, juicy couture outlet, nike air max, converse outlet, barbour jackets, moncler, ugg,ugg australia,ugg italia, links of london, moncler, gucci, canada goose outlet, canada goose, canada goose outlet, coach outlet, canada goose uk, ugg boots uk, canada goose, juicy couture outlet, ugg pas cher, wedding dresses, canada goose

Soni yadav said...

Aol Technical Support Phone Number
Aol Technical Support Number
Aol Tech Support Number
Aol Tech Support phone Number
Aol Support Phone Number
Aol Tech Support Number
Outlook Technical Support Phone Number
Outlook Technical Support Number
Outlook Tech Support Number
Outlook Tech Support Phone Number
Outlook Support Phone Number
Outlook Tech Support Number

roshini said...


Sage Support Phone Number
Sage 50 Tech Support Phone Number
Sage 50 Support Number
Sage 50 Technical Support Phone Number
Sage 50 Tech Support Number
Sage 50 Technical Support Phone Number
Sage 50 Technical Support Number
Sage 50 Customer Support Phone Number
Sage 50 Customer Service Number

Anjilo Jilo said...

Quicken Support Phone Number
Quicken Support Phone Number
Quicken Support Number
Quicken Tech Support Number
Quicken Tech Support Phone Number
Quicken Technical Support Number
Quicken Technical Support Phone Number
Quicken Technical Support Number
Quicken Tech Support Phone Number
Quicken Tech Support Number

mohan kumar said...

Quickbooks Support Phone Number
Quickbooks Premier Support Phone Number
Quickbooks Premier Tech Support Number
Quickbooks Premier Support Number
Quickbooks Premier Technical Support Number
Quickbooks Premier Tech Support Phone Number
Quickbooks Premier Technical Support Phone Number
Quickbooks Premier Help Desk Phone Number
Quickbooks Premier Help Desk Number
Quickbooks Premier Customer Service Number
Quickbooks Premier Customer Service Phone Number
Quickbooks Premier Customer Support Number
Quickbooks Premier Customer Support Phone Number

Kanika Jaiswal said...





QuickBooks Error Technician
Quickbooks Error Support Phone Number
Quickbooks Error Tech Support Number
Quickbooks Error Support Number
Quickbooks Error Technical Support Number
Quickbooks Error Tech Support Phone Number
Quickbooks Error Technical Support Phone Number
Quickbooks Error Help Desk Phone Number
Quickbooks Error Help Desk Number
Quickbooks Error Customer Service Number
Quickbooks Error Customer Service Phone Number
Quickbooks Error Customer Support Number
Quickbooks Error Customer Support Phone Number

Mohini Roy said...

Quicken Support Number
Quicken Support Phone Number
Quicken Tech Support Number
Quicken Support Number
Quicken Technical Support Number
Quicken Tech Support Phone Number
Quicken Customer Service Number
Quicken Customer Service Phone Number
Quicken Customer Support Number
Quicken Customer Support Phone Number
Quicken Help Desk Phone Number
Quicken Help Desk Number

Mohini Roy said...

Quicken Tech Support Number
Quicken Support Phone Number
Quicken Tech Support Number
Quicken Support Number
Quicken Technical Support Number
Quicken Tech Support Phone Number
Quicken Customer Service Number
Quicken Customer Service Phone Number
Quicken Customer Support Number
Quicken Customer Support Phone Number
Quicken Help Desk Phone Number
Quicken Help Desk Number