【问题标题】:REST_Controller.php is not working in codeigniterREST_Controller.php 在 codeigniter 中不起作用
【发布时间】:2016-12-28 07:39:20
【问题描述】:

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

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

通话时 localhost/rest_api_ci/api/example/user/1

显示错误

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

Example.php 文件一览

<?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()
    {

【问题讨论】:

  • 你把rest_controller.php放在你项目的什么地方?
  • libraries/REST_Controller.php 中的一切都在正确的位置。我正在使用 .htaccess 文件删除 index.php
  • 如果你在本地工作
  • @vipul sharma 你也在使用 MX_controller 吗?

标签: codeigniter


【解决方案1】:

更改您的网址
localhost/rest_api_ci/api/example/user/1

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

【讨论】:

【解决方案2】:

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

【讨论】:

    【解决方案3】:

    之后

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

    你需要添加命名空间:

    // use namespace
    
    use Restserver\Libraries\REST_Controller;
    

    ...几分钟前我遇到了这个问题,它对我有用

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2012-12-16
        • 2014-12-23
        • 2018-04-23
        • 2021-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多