2016-12-28 91 views
1

我打算使用REST_Controller.php来制作其余的api。上调用 本地主机/ rest_api_ci/API /示例/用户/ 1REST_Controller.php在codeigniter中不起作用

显示(使用笨V3上ubnatu 15)

从链路https://github.com/chriskacerguis/codeigniter-restserver

Me错误

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() 
    { 
+0

你在哪里放置rest_controller .php在你的项目中? –

+0

库/ REST_Controller.php一切都在正确的地方。我使用.htaccess文件删除index.php –

+0

所以你的网址必须是http://localhost/rest_api_ci/index.php/api/Example/users –

回答

0

您的网址从

localhost/rest_api_ci/api/example/user/1 

改变

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

仍然以http相同://localhost/rest_api_ci/index.php/api/Example/user/1和http://本地主机/ rest_api_ci/API /实施例/用户/ 2 –

+0

@vipul夏尔马:答案提供 –

+0

地方使用example.php API文件夹和更改URL HTTP之外://localhost/rest_api_ci/index.php/Example/users –

0

REST_Server.php移除不必要的命名空间和Format.php帮助了我。

0

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

您需要添加命名空间:

// use namespace 

use Restserver\Libraries\REST_Controller; 

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