【问题标题】:Url Routing not working Rest Api codeigniter网址路由不起作用 Rest Api codeigniter
【发布时间】:2019-05-03 06:00:33
【问题描述】:

我正在使用 codeigniter 创建 rest api 并想使用函数但在点击“http://localhost/codeigniter-rest-api-master/api/testing”后显示错误 “404 页面未找到”。我错在哪里?

这是我的“application/config/routes.php”

   $route['api'] = 'api/users/';
    //api/users
    $route['api/users'] = 'api/testing/testing/';
    $route['api/users/format/json'] = 'api/testing/testing/format/json';
    $route['api/users/format/xml'] = 'api/testing/testing/format/xml';
    $route['api/users/format/html'] = 'api/testing/testing/format/html';
    $route['api/users/format/csv'] = 'api/testing/users/format/csv';
    $route['api/users.json'] = 'api/testing/testing.json';
    $route['api/users.xml'] = 'api/testing/testing.xml';
    $route['api/users.html'] = 'api/testing/testing.html';
    $route['api/users.csv'] = 'api/testing/testing.csv';

这是我的“应用程序/控制器/api/Users.php”

public function testing()
{
    echo "hello world";

}

【问题讨论】:

    标签: php rest codeigniter


    【解决方案1】:

    您没有api/testing 路由。使用类似的东西

    $route['api/testing'] = 'api/users/testing/';
    

    路由是folder/controller_class/function。我认为你应该阅读guide。 这个Answer 也会很有帮助。

    【讨论】:

    • 不工作(在控制器中我的控制器有文件夹名称“api”,其中用户控制器存在
    • 你是如何声明路由的?
    • 现在我得到了正确的结果 $route["Users"]["GET"] = "api/index_get";
    • 对你有好处。我目前也在尝试使用 CI 制作 rest api ;-)
    • 我正在使用 post 方法但无法正常工作,我可以知道为什么吗? $route["Users"]["POST"] = "api/index_get";
    猜你喜欢
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 2011-11-07
    • 2018-06-27
    相关资源
    最近更新 更多