5

iam using zend framework to build a REST web service and i am using modules to separate my api versions, as i have mentioned here

Ex: "applications/modules/v1/controllers", "applications/modules/v2/controllers" have different set of actions and functionality. I have mentioned my default module as "v1" in my application.ini

I am using context switching along with Regex Routing as i have mentioned here in my accepted solution:

$router->addRoute(
            'route1',
            new Zend_Controller_Router_Route_Regex(
                                            'api/([^-]*)/([^-]*)\.([^-]*)', 
                                            array(
                                                'controller'   => 'index',
                                                'action'       => 'index'),
                                            array(
                                                1 => 'module',
                                                2 => 'controller',
                                                3 => 'format'
                                            )
));

This is my url: http://localhost/api/v1/tags.xml

"v1" indicates module. Now, coming to context switching, if the url has v1, it is going to v1 module's TagsController. But if the module in url is v2, i am getting an error such as:

The requested URL /pt/public/index.php/api/v2/tags.xml was not found on this server.

I could not understand why its blowing up. Is it because i have put the default module as v1? I am not able to change the module based on the url.

And this is my directory tree:

  • application
    • modules
      • v1
        • controllers
          • TagsController.php
      • v2
        • controllers
          • TagsController.php
  • library
4
  • You should be looking into a RESTful API System Commented Mar 3, 2011 at 9:26
  • I am already using a RESTful API system. I have edited my question with more info. Commented Mar 3, 2011 at 12:18
  • need more details. we need the directory tree from your application's root folder Commented Mar 3, 2011 at 13:02
  • Updated my answer with the directory tree... see, v1 and v2 are modules in my application, and default module is specified as v1 in application.ini file. Commented Mar 3, 2011 at 13:23

1 Answer 1

3

My goodness... i have figured out the solution... the controller class name in the v2 module must be "V2_TagsController", not just "TagsController". Thank God, it is working now :) See the class names for controllers below:

- application
      - modules
         - v1
            - controllers
                  - TagsController.php (class TagsController)
         - v2
            - controllers
                  - TagsController.php (class V2_TagsController)
- library
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.