Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP REST Basic Mapping Not Working As Expected

Followed the Cake Book example almost exactly.

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

Both before

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

My controller called IncidentReportsController

class IncidentReportsController extends AppController {

Which contains functions

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

Going to the URL

www.myurl.com/incidentReports.json

Sends the request to the index() function as expected.

Going to the URL

www.myurl.com/incidentReports/260.json

Should map to the view() function but trys to map to a 260() function which doesn't exist.

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

Does map to the view() function and works properly. However, my understanding is the "view" in the URL shouldn't be necessary.

like image 765
user2004338 Avatar asked Feb 27 '13 14:02

user2004338


1 Answers

Had the same issue. In my case I was able to fix it by changing the controller name in the URL.

Didn't work: http://www.example.com/entityName.json
Works fine: http://www.example.com/entity_name.json

like image 77
krani Avatar answered Sep 30 '22 12:09

krani