shohyuken Setiawan wrote on Friday 29th of July 2011:1. Is it possible to use the default behavior using $HTTP_RAW_POST_DATA with input and somehow deserialize it
abstract class Controller_Rest extends Fuel\Core\Controller_Rest
Autoloader::add_classes(array( 'Controller_Rest' => APPPATH . 'classes/extend/controller/rest.php' ));
if ( $data = file_get_contents('php://input'); AND $data = json_decode($data)) { array_push($arguments,$data); } // If method is not available, set status code to 404 if (method_exists($this, $controller_method)) { $response = call_user_func_array(array($this, $controller_method), $arguments); $this->response($response); } else { $this->response->status = 404; return; }This will add the raw post input as the last argument to the method being called (in case you are using GET parameters). Note that the above is my own code which also includes a "fix" that allows me to just return the resulting data in my REST services rather than having to call $this->response(). you might want to remove this, based on your preference.[/code] EDIT: Careful to fix the encoding errors in the above code, these forums have some serious bugs on them. Which is not helping sell the framework as a stable platform
shohyuken wrote on Friday 29th of July 2011:I am using backbone.js for my frontend. It's getting a little bit tricky to work it with fuel php Input class, here is why Backbone.js uses json to serialize its models back to the backend.
By default it will post the string as application/json and can be acquired through $HTTP_RAW_POST_DATA = 'json serialized string' but using Backbone.emulateJSON = true, the model saved will be under $_POST = 'json serialized string' as application/x-www-form-urlencoded My current solution is to have a "before" function in my REST api and use json_decode on the posted model. My questions are:
1. Is it possible to use the default behavior using $HTTP_RAW_POST_DATA with input and somehow deserialize it
2. how do I use the validation class? Can I pass an array/object to be validated instead of reading automatically from POST?
It looks like you're new here. If you want to get involved, click one of these buttons!