2016-12-28 79 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; 

...我幾分鐘前就遇到了這個問題,它和我一起