How to create/setup custom routing in ZendFramework

By | January 8, 2014

Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request.
In simple way, we can say that this is same as URL Rewriting in PHP we do.

Ex1 : Routing without variables

Now, say for example your domain is http://mydomain.com
And you want the http://mydomain.com/register/user to be http://mydomain.com/user-registration

Put the code below in Bootstrap.php file as

1
2
3
4
5
6
7
<?php
protected function _initRoute()
{
    $router = Zend_Controller_Front::getInstance()->getRouter(); //create object of a router
    $router->addRoute('registration',new Zend_Controller_Router_Route('user-registration',array('controller'=>'register','action'=>'user'))); //registration can be any text as you want
}
?>

Ex2 : Routing with variables

Now, say for example http://mydomain.com/product/10

Put the code below in Bootstrap.php file as

1
2
3
4
5
6
7
<?php
protected function _initRoute()
{
    $router = Zend_Controller_Front::getInstance()->getRouter(); //create object of a router
    $router->addRoute('myproduct',new Zend_Controller_Router_Route('product/:id',array('controller'=>'product','action'=>'index'))); //myproduct can be any text as you want 
}
?>

Hope, you will enjoy!

110 thoughts on “How to create/setup custom routing in ZendFramework

  1. melisa

    I do not even understand how I ended up here, but I believed
    this put up was good. I do not know who you’re however definitely you are
    going to a famous blogger in case you aren’t already.
    Cheers!

  2. Porfirio

    I feel this is one of the such a lot important information for me.
    And i’m happy studying your article. But should remark on few normal things, The
    website style is wonderful, the articles is in reality excellent : D.
    Excellent task, cheers

  3. rod

    Hello There. I found your weblog the usage of msn. That
    is an extremely smartly written article. I’ll make sure to
    bookmark it and come back to learn extra of your helpful information.
    Thanks for the post. I will definitely return.

  4. hilario

    Hello colleagues, how is the whole thing, and what
    you want to say regarding this article, in my view its genuinely awesome for me.

  5. nellepflaum

    Everything is very open with a clear clarification of the challenges.
    It was really informative. Your website is extremely helpful.
    Many thanks for sharing!

  6. kristy

    Very soon this website will be famous among all blogging and site-building viewers, due to it’s pleasant content

  7. gordoncranford

    If some one needs to be updated with newest technologies afterward he must be go
    to see this web page and be up to date everyday.

  8. carrolflorence

    Its such as you learn my mind! You appear to understand a lot approximately
    this, such as you wrote the ebook in it or something. I feel that you could do
    with a few percent to force the message
    home a bit, however instead of that, this is excellent blog.
    A great read. I’ll certainly be back.

  9. Grover

    Hi there I am so grateful I found your web site, I really
    found you by accident, while I was browsing on Aol for something else, Anyhow I am here now and would just like to
    say thanks for a marvelous post and a all round entertaining blog (I also love
    the theme/design), I don’t have time to look over it all at the minute but I
    have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the
    great b.

  10. hannelore

    It’s not my first time to pay a quick visit this site, i am
    visiting this web page dailly and take fastidious data from here all the
    time.

  11. freddy

    Hi there! Someone in my Facebook group shared this site with us
    so I came to check it out. I’m definitely enjoying the information.
    I’m book-marking and will be tweeting this to my followers!
    Superb blog and fantastic design.

  12. merrifarquharson

    This web site really has all the information I wanted concerning
    this subject and didn’t know who to ask.

  13. frankiegoebel

    It’s remarkable to go to see this site and reading the views of all friends about
    this piece of writing, while I am also zealous of getting knowledge.

  14. magdadorrington

    We are a group of volunteers and opening a new scheme in our community.

    Your website provided us with valuable info to work
    on. You’ve done a formidable job and our whole community will be grateful to
    you.

  15. elizabeth

    Wonderful site. Plenty of helpful info here. I’m sending it to some pals
    ans also sharing in delicious. And of course, thanks for your sweat!

  16. reynald

    Greetings I am so thrilled I found your webpage, I really found you by error,
    while I was browsing on Askjeeve for something else,
    Anyways I am here now and would just like to say kudos for a tremendous post and a all
    round enjoyable blog (I also love the theme/design), I don’t have time to read it all at the
    minute but I have bookmarked it and also added in your RSS feeds, so when
    I have time I will be back to read much more, Please do
    keep up the great work.

  17. carlisle

    Hello, i think that i saw you visited my weblog so i came to return the want?.I am attempting to in finding things to improve my web site!I assume its adequate to use some of your ideas!!

  18. wade dawson

    Great goods from you, man. I have take into accout
    your stuff previous to and you’re simply too great. I actually
    like what you have obtained here, really like what you’re saying and
    the way wherein you assert it. You make it enjoyable and you continue to take care of to stay
    it smart. I cant wait to learn much more from you.
    This is really a terrific web site.

  19. alberth

    Its not my first time to go to see this website, i am browsing this web page dailly and get good
    data from here daily.

  20. jean rodway

    I loved as much as you will receive carried out
    right here. The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get got an shakiness over that you wish be
    delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this increase.

  21. vicky

    hey there and thank you for your info – I’ve
    definitely picked up anything new from right here.

    I did however expertise several technical issues using this web site, as I experienced to reload the site lots
    of times previous to I could get it to load properly.
    I had been wondering if your hosting is OK? Not
    that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your
    high-quality score if ads and marketing with Adwords.
    Well I am adding this RSS to my email and can look out for much more of your respective fascinating content.

    Ensure that you update this again very soon.

  22. kim

    Very nice post. I just stumbled upon your weblog and wanted
    to say that I have really enjoyed surfing around your blog posts.
    In any case I’ll be subscribing to your feed and I hope you write again very soon!

  23. shelly

    Thank you a lot for sharing this with all of
    us you really recognize what you’re speaking about! Bookmarked.

    Please additionally discuss with my web site =).
    We can have a hyperlink trade arrangement among us

  24. Robot aspirador

    Hey I know this is off topic but I was wondering if you knew of
    any widgets I could add to my blog that automatically tweet my newest twitter updates.

    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like
    this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  25. Issac Maez

    I just want to say I am very new to weblog and really enjoyed your web-site. Probably I’m want to bookmark your blog . You really come with perfect well written articles. Cheers for sharing with us your web page.

  26. Gloryhopley

    Heya i’m for the first time here. I found this board and I find It truly useful &
    it helped me out much. I hope to give something back and help others like you helped
    me.

  27. Airline Tickets

    Hey fantastic blog! Does running a blog such as this take a massive amount work?
    I have no expertise in computer programming however
    I was hoping to start my own blog in the near future. Anyway, if you have any recommendations or tips for new blog owners please share.
    I understand this is off subject however I simply needed to ask.

    Kudos!

  28. Free picks and parlays

    I know this if off topic but I’m looking into starting my own blog and
    was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web savvy so I’m not 100% positive. Any suggestions or advice would be greatly appreciated.
    Thank you

  29. Franklyn

    Thank you for the auspicious writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you!
    However, how could we communicate?

  30. Weiss

    Thanks for your personal marvelous posting! I seriously enjoyed reading it, you might be a great author.I will remember to bookmark your blog and will often
    come back at some point. I want to encourage yourself to
    continue your great work, have a nice weekend!

  31. elvisrenteria

    I for all time emailed this webpage post page to all my contacts, for the reason that if like to read
    it next my friends will too.

  32. Nestortickell

    Hey There. I found your blog the use of msn. This is an extremely well written article.
    I’ll make sure to bookmark it and come back to learn extra of your helpful information.
    Thank you for the post. I’ll definitely return.

  33. Hipolito M. Wiseman

    I just want to mention I am all new to blogs and definitely liked you’re web site. Likely I’m likely to bookmark your website . You amazingly have fantastic stories. Thanks for revealing your blog.

  34. autumn

    If some one needs expert view regarding blogging and site-building afterward i recommend him/her to visit this
    website, Keep up the pleasant work.

  35. christal

    Howdy very nice site!! Guy .. Beautiful .. Wonderful ..

    I will bookmark your website and take the feeds also?
    I am happy to search out so many useful info here in the submit, we need develop more techniques in this regard, thank you for sharing.
    . . . . .

  36. online marketing tips and tricks

    Hello there! I could have sworn I’ve been to this web site before but after looking
    at many of the articles I realized it’s neww to me.
    Nonetheless, I’m certainly happy I found iit and I’ll be bookmarking it and
    checking back often!

  37. weight loss for teens

    My brother recommended I may like this web site. He was once entirely right.
    This publish actually made my day. You cann’t imagine simply how a lot time I had spent for this information!
    Thanks!

  38. search hotels

    Great post. I used to be checking constantly this weblog and I am impressed!

    Extremely useful information specifically the closing section :
    ) I deal with such information a lot. I was looking for this
    particular info for a very lengthy time. Thanks and good luck.

  39. Appliance Repair Las Vegas

    I blog quite often and I really thank you for your content.
    This great article has truly peaked my interest. I am going
    to bookmark your blog and keep checking for new details about once per week.

    I subscribed to your RSS feed as well.

  40. Bruno

    I do agree with all the concepts you have introduced to your post.
    They’re really convincing and can definitely work. Nonetheless, the posts
    are too quick for starters. May you please extend them a little from subsequent time?
    Thank you for the post.

  41. Bruno

    What’s up it’s me, I am also visiting this site regularly, this website is really good and the
    users are genuinely sharing pleasant thoughts.

  42. sbobet

    Good post. I learn something totally new and challenging on websites I stumbleupon every day.

    It will always be exciting to read through content from other writers and practice a little something from other websites.

  43. sbobet

    Wonderful site you have here but I was curious about if you knew of any discussion
    boards that cover the same topics discussed here?

    I’d really love to be a part of online community where I can get comments from other
    knowledgeable individuals that share the same interest. If you have any suggestions,
    please let me know. Kudos!

  44. sbobet

    We are a group of volunteers and starting a new scheme in our community.
    Your site provided us with valuable information to work on.
    You’ve done an impressive job and our entire community will be thankful
    to you.

  45. Matthew C. Kriner

    I just want to say I am beginner to blogging and truly savored your page. More than likely I’m planning to bookmark your blog . You actually come with exceptional articles. Appreciate it for sharing with us your website.

  46. fifa 14 key generator download

    Hi just wanted to give you a brief heads up and let you know a
    few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue.

    I’ve tried it in two different web browsers and both show the
    same outcome.

  47. tummy tuck in Buffalo

    Hmm it looks like your site ate my first comment (it was super long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying
    your blog. I too am an aspiring blog writer but I’m still new to everything.
    Do you have any points for beginner blog writers? I’d really
    appreciate it.

  48. Marco

    Very nice post. I just stumbled upon your weblog
    and wanted to say that I’ve really enjoyed browsing
    your blog posts. After all I will be subscribing
    to your feed and I hope you write again very soon!

  49. seofornowandforever.com

    Excellent post. I was checking continuously this blog and I’m impressed!

    Very useful info specifically the last part :) I care for such information much.
    I was seeking this particular info for a very long time.

    Thank you and best of luck.

  50. epicshoe.com

    Hi I am so glad I found your site, I really found you by accident, while I was searching on Digg for something
    else, Nonetheless I am here now and would just like
    to say kudos for a incredible post and a all round exciting
    blog (I also love the theme/design), I don’t have time to read it all at the
    minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read
    much more, Please do keep up the fantastic work.

  51. seofornowandforever.com

    My partner and I stumbled over here by a different website and thought I may as well check things
    out. I like what I see so i am just following you. Look forward to
    finding out about your web page for a second time.

  52. Search Hotels

    Howdy I am so glad I found your blog page, I really found you
    by error, while I was browsing on Google for something else, Anyways I am here now and would just like to say thanks for a marvelous post and a all round
    entertaining blog (I also love the theme/design), I don’t have
    time to read through it all at the minute but I have bookmarked it and also included your RSS feeds, so when I have
    time I will be back to read more, Please do keep up the great work.

  53. WhatsApp PC

    Remarkable issues here. I am very satisfied to see your post.

    Thank you so much and I am having a look forward
    to contact you. Will you kindly drop me a e-mail?

  54. m88

    This is really interesting, You’re a very skilled
    blogger. I’ve joined your feed and sit up for searching for more of your fantastic post.

    Additionally, I have shared your website in my social networks

  55. Andrew Pelt

    I just want to tell you that I am very new to blogs and actually loved your web blog. Almost certainly I’m planning to bookmark your website . You actually come with outstanding stories. Thanks for sharing with us your web-site.

  56. Burton Haynes

    I simply want to tell you that I am just very new to weblog and really loved your blog site. Most likely I’m going to bookmark your blog . You actually have incredible posts. Appreciate it for revealing your website.

  57. chiropractie sherbrooke

    Simply desire to say your article is as amazing.
    The clearness in your post is just great and i can assume you are
    an expert on this subject. Well with your permission let me to grab your feed
    to keep up to date with forthcoming post. Thanks a million and please carry on the enjoyable work.

Leave a Reply