php - cakephp rest api POST request invokes index() rather than add() -


i'm working on cakephp json rest api --

i'm following rest tutorial @ http://book.cakephp.org/2.0/en/development/rest.html , testing via chrome extension "advanced rest client"

the route can function expected index() via request -- returns me array of test data (as expected)

when post attempt create new record, receive 404, added test data db in order try request recipe id (a 36char uuid field) , request routes index() function.

i'm receiving following response when try simple request:

{ code: 404 url: "/users/d8d9701e-2f6e-11e3-af16-2513f388d17e" name: "action userscontroller::d8d9701e-2f6e-11e3-af16-2513f388d17e() not found." } 

the request here users/d8d9701e-2f6e-11e3-af16-2513f388d17e

in routes.php file:

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) ));  router::mapresources('users'); router::parseextensions('json'); 

my userscontroller.php looks : http://pastebin.com/bdxrlbtp

note commented access control rule seems have no effect on issues. i've tried , without control rule, i'm not 100% positive exists in right place, anyway. thought post wasn't working because of cors issues. however, not explain issues when trying find specific record.

according tutorial feel shouldn't need router::resouremap function, threw in anyway in case. i've tried putting below router::mapresources call -- in tutorial says:

"by overwriting default resource map, future calls mapresources() use new values."

so i'm pretty sure needs called before calling mapresources()

thanks!

the issue apparently had functions in wrong area of routes.php file.

as per: cakephp - rest post functionality not working default mapping

in routes.php had following last lines of file.

router::mapresources('users'); router::parseextensions('json'); 

they needed moved above line:

require cake . 'config' . ds . 'routes.php'; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -