CodeIgniter Forums
Fatal error: Class 'CI_Myapi' not found in /var/www/castle_invoice_api/sys... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Fatal error: Class 'CI_Myapi' not found in /var/www/castle_invoice_api/sys... (/showthread.php?tid=63859)



Fatal error: Class 'CI_Myapi' not found in /var/www/castle_invoice_api/sys... - bala025 - 12-16-2015

<b>Fatal error</b>:  Class 'CI_Myapi' not found in <b>/var/www/castle_invoice_api/system/core/Common.php</b> on line <b>196</b><br />

I have got this error.Please tell me how to resolve this.My code is

application/config/autoload.php

$autoload['libraries'] = array('Myapi');


application/controllers/Main.php

defined('BASEPATH') OR exit('No direct script access allowed');

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

interface MyInterface {

public function disp();

}

class Myadapter extends REST_Controller implements MyInterface {

public function __construct()
{
// Construct the parent class
parent::__construct();
}

public function disp()
{
        return 'sample msg';
}
}

class Main extends REST_Controller {
public $client = FALSE;
public function __construct()
{
// Construct the parent class
parent::__construct();

$this->__authenticate();
}

public function index_post()
{
$resp = new stdClass();
    $resp->status = false;
    $resp->message = 'something went wrong';

$api = $this->Gateway('api1');

$resp->message = $api->disp();
$this->response($resp, 400);
}
private function __authenticate()
{
        $this->client = $this->myapi->__authenticate();
}

private function Gateway($type='')
{
        switch($type) {
      case "api1":
        $api = new Myadapter();
        return $api;
        break;
      case "api2":
        $api = new Myadapter1();
        return $api;
      break;
      default:
        // Do something to log an exception
        return false;
        break;
   }
}
}


RE: Fatal error: Class 'CI_Myapi' not found in /var/www/castle_invoice_api/sys... - arma7x - 12-16-2015

Remove CI_ suffix.


RE: Fatal error: Class 'CI_Myapi' not found in /var/www/castle_invoice_api/sys... - kenjis - 12-16-2015

Because Myadapter is a controller.
You can't instantiate controllers in CI.

Remove ` extends REST_Controller` of Myadapter.