CakePHP REST base mapping does not work as expected

Followed the cake example. About for sure.

Router::mapResources('incidentReports'); Router::parseExtensions('json'); 

Both before

 require CAKE . 'Config' . DS . 'routes.php'; 

My controller is called IncidentReportsController

 class IncidentReportsController extends AppController { 

What contains the functions

 index() view($id) add() edit($id) delete($id) 

Go to URL

 www.myurl.com/incidentReports.json 

Sends a request to index () as expected.

Go to URL

 www.myurl.com/incidentReports/260.json 

You must map the view () functions, but try to map the 260 () function, which does not exist.

 www.myurl.com/incidentReports/view/260.json 

Whether the view () function is displayed and is working correctly. However, I understand that the “submission” in the URL should not be necessary.

+6
source share
3 answers

There was the same problem. In my case, I was able to fix this by changing the name of the controller in the url.

Doesn't work: http://www.example.com/entityName.json
Works great: http://www.example.com/entity_name.json

+3
source

According to the documentation , you did everything right, so I'm not sure. Try putting this (routes that should be included) on your routes.

 Router::resourceMap(array( array('action' => 'index', 'method' => 'GET', 'id' => false), array('action' => 'view', 'method' => 'GET', 'id' => true), array('action' => 'add', 'method' => 'POST', 'id' => false), array('action' => 'edit', 'method' => 'PUT', 'id' => true), array('action' => 'delete', 'method' => 'DELETE', 'id' => true), array('action' => 'update', 'method' => 'POST', 'id' => true) )); 
0
source

If your controller is inside the plugin, you must also specify.

for example: Router :: mapResources ('Plugin.Controller');

0
source

All Articles