5
votes

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
1
You should be looking into a RESTful API SystemRobertPitt
I am already using a RESTful API system. I have edited my question with more info.shasi kanth
need more details. we need the directory tree from your application's root folderLenin Raj Rajasekaran
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.shasi kanth

1 Answers

3
votes

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