【发布时间】:2016-12-02 07:30:17
【问题描述】:
<?php
include(APPPATH.'/libraries/REST_Controller.php');
class Quiz extends REST_Controller{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function user_get()
{
$this->load->model('Quizmodel');
$data = $this->Quizmodel->getAll();
$this->response($data, 200);
}
function restclient()
{
$this->load->library('rest', array(
'server' => 'http://localhost/CodeIg/index.php/quiz/'
));
$userr = $this->rest->get('user','','json');
echo $userr;
}
}
?>
如果我在浏览器中输入 http://localhost/CodeIg/index.php/quiz/user,我可以获得 JSON 输出,但是如果我输入 http://localhost/CodeIg/index.php/quiz/restclient,则会出现以下错误:{"status":false,"error":"Unknown method"}
我尝试将get 更改为post,但仍然是同样的错误。
我参考了这个页面https://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814来做这件事。
【问题讨论】:
标签: php codeigniter