0

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
    }
woninana
  • 3,409
  • 9
  • 42
  • 66
  • Your not extending it, it should be `class MY_Controller extends REST_Controller` – Lawrence Cherone Oct 10 '18 at 22:30
  • I edited my question please see again above – woninana Oct 10 '18 at 22:34
  • 1
    Well that's different lol, Did you read the error? `Call to undefined method Phone::post()`.. where is the post method in the controller I only see `index_get` – Lawrence Cherone Oct 10 '18 at 22:36
  • apologies @LawrenceCherone, edited `$this->post` to `$this-get` to match the function name but its still showing `Call to undefined method Phone::get()` its the same error i get, so assumed the REST API is not working yet – woninana Oct 11 '18 at 13:21

0 Answers0