首页 文章

REST_Controller.php在codeigniter中不起作用

提问于
浏览
2

我将使用REST_Controller.php来制作休息api . (在ubnatu 15上使用codeigniter v3)

来自链接https://github.com/chriskacerguis/codeigniter-restserver

在调用localhost / rest_api_ci / api / example / user / 1时

Showing me error

Fatal error: Class 'REST_Controller' not found in /var/www/html/rest_api_ci/application/controllers/api/Example.php on line 21

A look of Example.php file

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
/** @noinspection PhpIncludeInspection */
require(APPPATH.'libraries/REST_Controller.php');


/**
 * This is an example of a few basic user interaction methods you could use
 * all done with a hardcoded array
 *
 * @package         CodeIgniter
 * @subpackage      Rest Server
 * @category        Controller
 * @author          Phil Sturgeon, Chris Kacerguis
 * @license         MIT
 * @link            https://github.com/chriskacerguis/codeigniter-restserver
 */
class Example extends REST_Controller {

    function __construct()
    {

4 回答

  • 0

    require(APPPATH.'libraries/REST_Controller.php');
    

    你需要添加名称空间:

    // use namespace
    
    use Restserver\Libraries\REST_Controller;
    

    ...几分钟前我遇到了这个问题,它和我一起工作

  • 0

    我认为它的路径问题,给出了相同的答案here
    希望它能帮助你或其他人 .
    谢谢

  • 0

    改变你的网址

    localhost/rest_api_ci/api/example/user/1
    

    http://localhost/rest_api_ci/index.php/api/Example/users
    
  • 0

    删除 REST_Server.phpFormat.php 中不必要的命名空间帮助了我 .

相关问题