首页 > 解决方案 > 网址路由不起作用 Rest Api codeigniter

问题描述

我正在使用codeigniter创建rest api并想使用函数,但是在点击“ http://localhost/codeigniter-rest-api-master/api/testing ”后显示错误“404 page not found”。我错了?

这是我的“应用程序/配置/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";

}

标签: phprestcodeigniter

解决方案


你没有api/testing路线。使用这样的东西

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

路线是folder/controller_class/function。我认为你应该阅读指南。这个答案也会有帮助。


推荐阅读