1

i'm working with codeigniter rest server by phil sturgeon. I'm following net.tutsplus tutorial for restfull services here . I've installed the rest server locally and working intially to see how it works before installing it on server.

I'm having alot of problems from the starts. i included the REST_Controller.php file in my main controller and after that line when i do this :

 class Courses extends REST_Controller {

  function index (){
  $this->load->view('index');
  }

}

it gives error saying: Fatal error: Class 'REST_Controller' not found. But if i replace REST_Controller with CI_Controller it loads the index view. I'm stuck on this for 4 hours and nothing is working my way. need your advice guyz thnx in advance

3 Answers 3

3

From the docs: https://github.com/philsturgeon/codeigniter-restserver#installation

Quick way would be to add before class Courses extends REST_Controller {

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

Also, consider using __autoload Using the PHP spl_autoload_register() with Codeigniter

HTH

Sign up to request clarification or add additional context in comments.

1 Comment

Also the function name becomes index_get(). If your method is post then function should end with _post.
0

It should be something like this

class Courses extends REST_Controller {

 function index_get (){
   $this->response(array('success' => 'Yes it is working'), 200);
 }

}

Comments

0

Add this function on the top of your config.php file. In this way you don't need to include any file to any controller who extends REST_Controller.

function __autoload($classname) {
    if (strpos($classname, 'CI_') !== 0) {
        $file = APPPATH . 'libraries/' . $classname . '.php';
        if (file_exists($file) && is_file($file)) {
            @include_once($file);
        }
    }
}

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.