I am using the rest API in Yii. I want to implement an update function using PUT
, but it doesn't work and always returns an unchanged result from the database.
public function actionUpdate(){
$json = file_get_contents('php://input');
echo $json;
$put_vars = CJSON::decode($json,true); //true means use associative array
echo count($put_vars);
...
The above code is my function. I detected the problem in line $put_vars = CJSON::decode($json,true); because $json is not empty after submitting key/value pairs, but after decoding, the data becomes empty.
You may try in some rest client and see results by yourself: http://www.taxitaxi.kz/dispatcher/index.php/api/test/1
key/value: rating/8
echo of $json gives following response:
string(232) "------WebKitFormBoundarypsSvnRl0DUwJooRP Content-Disposition: form-data; name="rating"
8 ------WebKitFormBoundarypsSvnRl0DUwJooRP Content-Disposition: form-data; name="date"
333 ------WebKitFormBoundarypsSvnRl0DUwJooRP--
key/value pairs was: rating/8, date/333
Is it parceble json response?