Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4012812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:17:38+00:00 2026-05-20T09:17:38+00:00

i am developing a Rest Controller with Zend and i am confused with the

  • 0

i am developing a Rest Controller with Zend and i am confused with the mapping of urls to the Router.

Basically i read about Zend Router and i could not plan my urls in order to satisfy the mentioned routes.

These are some of my urls that should be mapped to Routers.

  1. http://localhost/api/v1/tags.xml

  2. http://localhost/api/v1/tags.xml?abc=true (param: abc=true)

  3. http://localhost/api/v1/tags/123456.xml (param: 123456.xml)

  4. http://localhost/api/v1/tags/123456/pings.xml (params: 123456, pings.xml)

  5. http://localhost/api/v1/tags/123456/pings.xml?a=1&b=2 (params: 123456, pings.xml, a=1, b=2)

  6. http://localhost/api/v1/tags/123456/pings/count.xml (params: 123456, pings, count.xml)

I am planning such that for the url patterns 1 to 3, “tags” should be the controller and for the url patterns 4 to 6, “pings” should be the controller.

Now i am unsure about how to configure the routers such that the above scenarios will work.
Note that i cannot change these urls. I can offer 100 of my reputation score to the good answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:17:39+00:00Added an answer on May 20, 2026 at 9:17 am

    First two URLs can be combined to one router.

    $r = new Zend_Controller_Router_Route_Regex('api/v1/tags.xml',
                    array('controller' => 'tags', 'action' => 'index'));
    $router->addRoute('route1', $r);
    

    To differentiate the first two routes, check for the presence of the abc parameter in your tags controller. Add the following in your tags controller, index action.

    if($this->_getParam('abc') == "true")
    {
    //route 2
    } else {
    // route 1
    }
    

    Similarly, routes 4 and 5 can be combined into one route.

    I have explained for Route 6. For route 3, you can use the same logic.

    $r = new Zend_Controller_Router_Route_Regex('api/v1/tags/(.*)/pings/(.*)',
                    array('controller' => 'pings', 'action' => 'index'),
    array(1 => 'param1',2=>'param2')
    );
    $router->addRoute('route6', $r);
    

    The parameters can then accessed like the following in pings controller.

    $this->_getParam('param1') and $this->_getParam('param2')
    

    For Route 5 :

    $r = new Zend_Controller_Router_Route_Regex('api/v1/tags/(.*)/pings.xml',
                    array('controller' => 'pings', 'action' => 'index'),
    array(1 => 'param1')
    );
    $router->addRoute('route5', $r);
    

    The parameters (part of the URL after ?) will not be handled in the Router. By default, they will be passed to your controller.

    To get a specifc parameter value passed in your URL, use the following in your controller.

    $this->_getParam('a');
    

    The logic is use (.*) in your route and assign them a parameter name and access them in your controller

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i used Zend Rest Controller for developing a web service, and now i need
i am developing a Rest Controller using Zend Framework and i have to use
I'm developing a REST service, so a request could be something like this: /Data/Main/Table=Customers/
I'm developing a REST CodeIgniter Controller and need to POST and PUT to a
m developing rest api by zf. this is my user controller. <?php class UserController
I'm about to start developing a REST API for a client's website and I've
I'm developing a REST api. To simplify my question, I have an API that
I'm developing a REST API at the moment, and one of the core features
I'm developing a REST-ful web service using RESTEasy deployed on Tomcat. I've configured an
I'm going to be developing a REST-ful Web Service for a new public website.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.