Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Rest_Route not working for a sub-directory controller (e.g. admin/questions)

I'm trying to define RESTful routes for sub directory controllers. I want to be able to create routes for the url at admin/questions/*. My controller is Admin_QuestionsController:

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

Below is how I'm declaring 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 can't 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 get the routes to work when I declare then not as Rest routes:

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

..so I don't think I've have the folder structure wrong, or the class name. But, I need RESTful routes which I'm unable to achieve.

like image 603
Martyn Avatar asked Apr 18 '15 11:04

Martyn


1 Answers

The Zend_Rest_Route route like you have defined, works if you have Zend modules enabled. The documentation mentions "translating the HTTP method and the URI to a module, controller and action". To enable modules, add the following two lines in your 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.

like image 75
Wouter Thielen Avatar answered Oct 03 '22 16:10

Wouter Thielen