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

  • Home
  • SEARCH
  • 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 633221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:09:41+00:00 2026-05-13T20:09:41+00:00

I’m trying to implement a REST API to my website. My problem is that

  • 0

I’m trying to implement a REST API to my website.

My problem is that the default Zend routing gets in the way. I’ve first tried using Zend_Rest_Route but I haven’t been able to understand how I was supposed to use it correctly for “deep” routes, aka website/api/resource1/filter/resource2/id.

Using the default Zend routing, I’d need to create a gigantic Resource1Controller to take care of all the possible actions, and I don’t think it’s the “good” way to do this.

I’ve tried using Resauce ( http://github.com/mikekelly/Resauce/), creating an api module and adding routes, but I’m not able to get it working correctly :

The patterns I added were :

    $this->addResauceRoutes(array(
        'api/resource' => 'resource',
        'api/resource/:id' => 'custom',
        'api/resource/filter' => 'resource-filter',
        'api/resource/filter/:id' => 'custom',
    ));

Which then leads to this :

public function addResauceRoutes($routes) {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    foreach ($routes as $pattern => $controller) {
        $router->addRoute($controller,
            new Zend_Controller_Router_Route($pattern, array(
                'module' => 'api',
                'controller' => $controller
                )
            )
        );
    }
    Zend_Controller_Front::getInstance()->setRouter($router);
  • website/api/resource gets me the
    Resource1Controller, ok
  • website/api/resource/filter gets me to the
    resource1filterController, ok
  • website/api/resource/filter/:id gets me to
    a custom controller, ok
  • I’d like for website/api/resource/:id to get me to the same custom controller… But it redirects me to the Resource1Controller.

What solution is there for me to correctly create my API ? Is there a good way to do this with Zend_Rest_Route ?


Edit : Mike,

I felt that it was not appropriate for me to use different controllers since I need the pathes “website/api/resource/:id” and “website/api/resource/filter/:id” to give me almost the exact same result (the only difference is that because the filter is there, I may get a message telling “content filtered” here).

I thought it was a waste creating another almost identical controller when I could’ve used the same controller and just checked if a parameter “filter” was present.

However, I don’t want to use the basic Zend routing since for the path “website/api/resource/filter/resource2” I’d like to have a totally different comportment, so I’d like to use another controller, especially since I’m trying to use Zend_Rest_Action and need my controllers to use the basic actions getAction(), putAction(), postAction() and deleteAction().

  • 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-13T20:09:42+00:00Added an answer on May 13, 2026 at 8:09 pm

    Please could you explain why it is you need two URI patterns pointing to the same controller. A better solution might be to use a separate controller for each of the two patterns and move any shared logic into your model.

    Forcing a unique controller for each routing pattern was an intentional design decision, so I’d be interested to hear more detail about your use case where you feel this isn’t appropriate.


    I thought it was a waste creating
    another almost identical controller
    when I could’ve used the same
    controller and just checked if a
    parameter “filter” was present.

    Personally, I think it is cleaner to move the shared logic into the model and to keep your controllers skinny. To me it’s not wasteful, it’s just more organised – it will make your code easier to manage over time.

    If you really need to use the same controller you could always use a query parameter instead, that would work fine:

    api/resource/foo?filter=true
    

    That URI would be taken care of by the first route (‘api/resource/:id’ => ‘custom’) for free.

    But please consider using two controllers, I think that is a better approach.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.