Zend Regex > Route module problem
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, com开发者_StackOverflow社区ing 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
- controllers
- v2
- controllers
- TagsController.php
- controllers
- v1
- modules
- library
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
精彩评论