我試圖與$this->post()
一起使用以json格式發送郵件。由於我無法得到任何結果,例如$this->post('name')
。
這是代碼:
<?php
require(APPPATH . '/libraries/REST_Controller.php');
class user_api extends REST_Controller {
function user_post() {
$user = array(
'id' => null,
'firstname' => $this->post('firstname'),
'lastname' => $this->post('lastname')
);
$result = $this->user_model->insert($user);
if ($result) {
$this->response($result, 200); // 200 being the HTTP response code
} else {
$this->response(NULL, 404);
}
}
}
?>
數據的JSON格式發送到鏈接:http://mydomain.com/myapplication/user_api/user:
{"firstname":"test",
"lastname":"test"
}
有數據庫中沒有任何數據,如它不能從$this->post('firstname')
獲取數據。
任何想法????你無法通過郵寄方式獲得
它的工作就像一個魅力非常感謝你。 – Madhawas