【问题标题】:{"status":false,"error":"Unknown method"} error CodeIgniter RESTful API{"status":false,"error":"未知方法"} 错误 CodeIgniter RESTful API
【发布时间】: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


    【解决方案1】:

    你在 GitHub 上 ping 我,尽管我至少有 4 年没有使用甚至考虑过这段代码了。

    https://github.com/chriskacerguis/codeigniter-restserver/blob/d19dc77f03521c7a725a4555407e1e4e7a85f6e1/application/libraries/REST_Controller.php#L680

    这是触发错误的地方。在那里或var_dump() 中设置几个断点,直到你看到导致问题的原因。

    不过,您可能想离开 CodeIgniter,并使用更积极维护的东西,例如 SlimPHPLumen

    【讨论】:

      【解决方案2】:

      首先我想要你已经加载了rest api并将你的控制器测验创建为一个api来调用,你只能创建像user_get或restclient_get这样的函数并以你正在做的相同方式访问它们。只需更改你的函数名称restclient到 restclient_get 然后它会调用而不是它现在甚至没有运行。

      【讨论】:

        猜你喜欢
        • 2014-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-28
        相关资源
        最近更新 更多