Unable to locate the specified class: Session.php
Just loaded the codeigniter-restserver to an existing project that is using the session class then I get this error. It comes when I autoload the session library.
Hi @bakasajoshua
You loaded it with composer?
If yes, then you changed composer_autoload in config.php like this:
$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');
Right?
You loaded your library in config/autoload.php? If you did as I said and you still have a bug then please give us your directory structure.
I have loaded it in config/autoload.php
Sorry I had loaded in the child class like so (require BASEPATH . 'libraries/REST_Controller.php';) and got the session error.
When I changed to config/autoload.php it gave an error "Cannot instantiate abstract class REST_Controller:
- Step In application/config/config.php set composer_autoload path like this:
$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');
- Step Load all other codeigniter's libraries that you need in application/config/autoload.php
$autoload['libraries'] = array('database', 'session');
The error
Cannot instantiate abstract class REST_Controller:
says, you dont extend the class correctly. I Think you try to use it direct.
Write your own Controller and only extend REST_Controller like:
class My_Rest_Controller extends REST_Controller
{
...
}
I have not used composer
Ok :)
So, you copied REST_Controller.php and Format.php in application/libraries and rest.php in application/config?
If yes, then add this on top of your controller:
require APPPATH . 'libraries/REST_Controller.php';
After this you can extend REST_Controller and use all features.
class My_Rest_Controller extends REST_Controller
{
...
}
@farukgaric I have done this and have also autoload the session library that is why am getting the error "Unable to locate the specified class: Session.php". When I do not autoload the session class it works fine.
But I need to autoload the session library for the rest of the application to work.
Ok. Did you try to load it manually in your controller
$this->load->library('session');
@farukgaric Yes I did, when I do, it works but cannot load my other custom libraries.
@farukgaric this sounds not like a probem with the Restserver. This sounds more like a problem with your codeigniter installation/libraries.
@farukgaric @Hanisch-IT I created my own controller that extends the CI_Controller which is loaded by the entire application apart from the API then I loaded the libraries there and it has worked like a charm :)
@chriskacerguis, this issue is ready to close :)
bagaimana cara mengatasi hal ini? Unable to locate the specified class: Session.php saya memakai versi 18.10 dan berusaha menambahkan update rilis pasca 2.12 (opensid rbac) salam..
any solution?
any solution?
@dbudihartono udah ketemu gan?
the problem occur because we use CI + HMVC this is the solution
- open file REST_Controller.php
- change "abstract class REST_Controller extends CI_Controller" to "abstract class REST_Controller extends MX_Controller"
- save the file, done!
@dbudihartono , @ib-ganz , @anjaneyulugulla masalah ini terjadi karena menggunakan CI + HMVC solusinya begini:
- buka file REST_Controller.php
- ubah "abstract class REST_Controller extends CI_Controller" ke "abstract class REST_Controller extends MX_Controller"
- save, selesai!
I have the same problem :(