Zend_Rest_Route does not work for the subdirectory controller (e.g. admin / questions)

I am trying to define RESTful routes for subdirectory controllers. I want to be able to create routes for the url in admin/questions/* . My controller: Admin_QuestionsController:

 - application - controllers -Admin QuestionsController.php (class Admin_QuestionsController) 

The following shows how I declare my RESTful route for this controller:

 $restRoute = new Zend_Rest_Route($front, array(), array( 'admin' => array('questions') )); $router->addRoute('rest', $restRoute); 

.. from the documentation I do not see what I'm doing wrong - http://framework.zend.com/manual/1.12/en/zend.controller.router.html#zend.controller.router.routes.rest . However, I get the following error:

 Invalid controller specified (admin) 

I can make routes work when I declare then not as recreation routes:

 $router->addRoute('admin_questions', new Zend_Controller_Router_Route( '/admin/questions', array( 'controller' => 'Admin_Questions', 'action' => 'index') ) ); 

..so I don’t think I have the wrong folder structure or class name. But I need RESTful routes that I cannot reach.

+7
php zend-framework
source share
1 answer

The Zend_Rest_Route route, as you have determined, works if you have Zend modules enabled. The documentation mentions "translating the HTTP method and URI to module, controller, and action." To enable modules, add the following two lines to application.ini :

 resources.modules[] = resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" 

Then create a directory in application/modules named admin/controllers and create your QuestionsController in application/modules/admin/controllers/QuestionsController.php .

The rest of your application should (hopefully) still work as the default module.

+3
source share

All Articles