Monday, October 4, 2010

Re: rest PUT request and parameters

I'm also trying to do the same thing. Unfortunately PHP in general
doesn't seem to be very good about dealing with PUTs. See:
http://php.net/manual/en/features.file-upload.put-method.php
http://www.php.net/manual/en/reserved.variables.request.php
http://www.php.net/manual/en/function.http-get-request-body.php#98142

Peter Robinett

On Sep 15, 9:59 am, MDD <marcello.duarte....@gmail.com> wrote:
> I've implemented REST routing in cakePHP to properly route REST style
> requests to the proper methods in my controller.
>
> This is what I've added to my routes.php
>
> Router::mapResources(array('object_fields'));
> This properly routes the REST requests to my index/add/edit/delete
> methods inside my controller.
>
> My GET/POST requests are being properly routed to my index/add methods
> inside my controller and I am able to easily retrieve the paramaters
> that I pass it in the request.
>
> My problem is with the update functionality PUT request. The PUT
> request does get successfully routed to my edit method inside the
> controller.
>
> This is what the request looks like in firebug
>
> http://server.local/object_fields/20
> JSON
> data
> Object { name="test7777777777", more...}
> id
> "18"
> Source
> {"id":"18","data":{"name":"test7777777777","id":"20"}}
>
> Inside my edit method I'm not receiving my array that I passed through
> the PUT request. When I dump $this->params inside my edit method this
> is what is in the array.
>
> ([id] => 20
> [named] => Array
>     (
>     )
>
> [pass] => Array
>     (
>         [0] => 20
>     )
>
> [controller] => object_fields
> [action] => edit
> [[method]] => PUT
> [plugin] =>
> [url] => Array
>     (
>         [ext] => html
>         [url] => object_fields/20
>     )
>
> [form] => Array
>     (
>     )
>
> [isAjax] => 1
> )
>
> The only way I am able to retrieve my array that I passed with PUT is
> the following code inside my controller:
>
>         function edit($id){
>                 $this->autoRender = false;
>                 echo 'edit';
>
>                  $raw  = '';
>             $httpContent = fopen('php://input', 'r');
>             while ($kb = fread($httpContent, 1024)) {
>                 $raw .= $kb;
>             }
>             fclose($httpContent);
>             $params = array();
>             parse_str($raw, $params);
>
>                 print_r($params);
>
>         }
>
> Is there a more 'auto-magic' way of acomplishing this through some
> kind of default behavior inside cake that I am missing?
>
> Thank you advance to anyone who can provide more insight into this
> problem.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: