2

I am going to use REST_Controller.php to make rest api's. (using codeigniter v3 on ubnatu 15)

from link https://github.com/chriskacerguis/codeigniter-restserver

on calling 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()
    {
9
  • where do you place rest_controller.php in your project? Commented Dec 28, 2016 at 7:45
  • in libraries/REST_Controller.php everything is in right place . I am using .htaccess file to remove index.php Commented Dec 28, 2016 at 7:46
  • so your url must be localhost/rest_api_ci/index.php/api/Example/users Commented Dec 28, 2016 at 7:48
  • if u r working on localhost Commented Dec 28, 2016 at 7:48
  • @vipul sharma are you using MX_controller also? Commented Dec 28, 2016 at 8:06

4 Answers 4

0

change your url from

localhost/rest_api_ci/api/example/user/1

to

http://localhost/rest_api_ci/index.php/api/Example/users
Sign up to request clarification or add additional context in comments.

6 Comments

@vipul sharma : answer provided
place example.php outside api folder and change url localhost/rest_api_ci/index.php/Example/users
Not working because "class Example extends REST_Controller" is not working
Anyone found solution?
|
0

Removing Unnecessary Namespaces in REST_Server.php and Format.php helped me.

Comments

0

After

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

you need to add the namespace:

// use namespace

use Restserver\Libraries\REST_Controller;

... I ran into this issue few minutes ago and it worked with me

Comments

0

I think its the path issue, same answer is given here
Hope it will help you or someone else.
Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.