0
votes
<?php
include(APPPATH.'/libraries/REST_Controller.php');
class Quiz extends REST_Controller{
function __construct()
{
    // Call the Model constructor
    parent::__construct();
}
public function user_get()
{
$this->load->model('Quizmodel');
$data = $this->Quizmodel->getAll();
$this->response($data, 200);
} 

function restclient()
{

$this->load->library('rest', array(
    'server' => 'http://localhost/CodeIg/index.php/quiz/'
));

$userr = $this->rest->get('user','','json');

echo $userr;
}

}
?>

I am able to get JSON output if I type http://localhost/CodeIg/index.php/quiz/user in my browser, however if I type http://localhost/CodeIg/index.php/quiz/restclient it gives this error: {"status":false,"error":"Unknown method"}

I tried changing get to post but still the same error.

I referred this page https://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814 to do it.

2

2 Answers

0
votes

You pinged me on GitHub, even though I haven't used or even thought about this code in at least 4 years.

https://github.com/chriskacerguis/codeigniter-restserver/blob/d19dc77f03521c7a725a4555407e1e4e7a85f6e1/application/libraries/REST_Controller.php#L680

This is where that error is being triggered. Throw a few breakpoints in there or var_dump()'s until you see what is causing the trouble.

You probably want to get off CodeIgniter though, and use something more actively maintained like SlimPHP or Lumen.

0
votes

firstly I want as you have loaded rest api and created your controller quiz as an api to call , where you can only create your functions like user_get or restclient_get and access them the same manner you are doing.Just change you function name restclient to restclient_get then it will call instead it is even not running at this moment.