I am trying to implement the following library in a new project.
"chriskacerguis/codeigniter-restserver": "^3.0"
I got a fresh codeigniter installation on my local server and I have done everything accordingly. Now I am trying to run the code its just showing the following error
Fatal error: Class Example cannot extend from trait Restserver\Libraries\REST_Controller in C:\xampp\htdocs\ci\application\controllers\api\Example.php on line 22 A PHP Error was encountered Severity: Compile Error
Message: Class Example cannot extend from trait Restserver\Libraries\REST_Controller
Filename: api/Example.php
Line Number: 22
Backtrace:
Code on line no 22 is as following
<?php
use Restserver\Libraries\REST_Controller;
defined('BASEPATH') OR exit('No direct script access allowed');
// Following line is line no 22
class Example extends REST_Controller {
function __construct()
{
// Construct the parent class
parent::__construct();
You have to modify provided (and outdated until this answer's date) versions of
application\libraries\REST_Controller.php
andapplication\controllers\api\Example.php
.application\libraries\REST_Controller.php
require APPPATH . 'libraries/REST_Controller_Definitions.php';
just beforetrait REST_Controller {
application\controllers\api\Example.php
class Example extends CI_Controller {
instead ofclass Example extends REST_Controller {
use REST_Controller { REST_Controller::__construct as private __resTraitConstruct; }
as the first line afterclass Example extends CI_Controller {
parent::__construct();
and$this->__resTraitConstruct();
to__construct()
function.$this->response($users, 200);
instead of$this->response($users, REST_Controller::HTTP_OK);
Hope it helps, it works for me.