I have the same exact issue with: Codeigniter 3 autoload controller
that I want to autoload the Libary automatically so I won't declare this:
use Restserver\Libraries\REST_Controller;
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 */
//To Solve File REST_Controller not found
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.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
*/
in every Controller. I tried extending it core/MY_Controller as suggested in the answer in the link I provided above, here's my core/MY_Controller.php looks like:
<?php
use Restserver\Libraries\REST_Controller;
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
}
?>
and upon running the controller/Example.php, methods from the rest api library is unknown. and having this error:
Message: Call to undefined method Phone::get()
Filename: C:\xampp\htdocs\mainline\application\controllers\api\Phone.php
Line Number: 16
Example.php
class Phone extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index_get()
{
$message = [
'id' => 100, // Automatically generated by the model
'name' => $this->get('name'),
'email' => $this->get('email'),
'message' => 'Invalid request'
];
$this->set_response($message, REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
}