codeigniter-restserver icon indicating copy to clipboard operation
codeigniter-restserver copied to clipboard

Unable to locate the specified class: Session.php

Open bakasajoshua opened this issue 9 years ago • 18 comments

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.

bakasajoshua avatar Sep 27 '17 13:09 bakasajoshua

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.

farukgaric avatar Sep 27 '17 13:09 farukgaric

I have loaded it in config/autoload.php

bakasajoshua avatar Sep 27 '17 14:09 bakasajoshua

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:

bakasajoshua avatar Sep 27 '17 14:09 bakasajoshua

  1. Step In application/config/config.php set composer_autoload path like this:
$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');
  1. Step Load all other codeigniter's libraries that you need in application/config/autoload.php
$autoload['libraries'] = array('database', 'session');

farukgaric avatar Sep 27 '17 14:09 farukgaric

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 
{
...
}

fabianblum avatar Sep 27 '17 14:09 fabianblum

I have not used composer

bakasajoshua avatar Sep 27 '17 14:09 bakasajoshua

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 avatar Sep 27 '17 14:09 farukgaric

@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.

bakasajoshua avatar Sep 27 '17 14:09 bakasajoshua

Ok. Did you try to load it manually in your controller

$this->load->library('session');

farukgaric avatar Sep 27 '17 14:09 farukgaric

@farukgaric Yes I did, when I do, it works but cannot load my other custom libraries.

bakasajoshua avatar Sep 27 '17 14:09 bakasajoshua

@farukgaric this sounds not like a probem with the Restserver. This sounds more like a problem with your codeigniter installation/libraries.

fabianblum avatar Sep 27 '17 18:09 fabianblum

@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 :)

bakasajoshua avatar Sep 28 '17 07:09 bakasajoshua

@chriskacerguis, this issue is ready to close :)

fabianblum avatar Sep 30 '17 23:09 fabianblum

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..

dbudihartono avatar Oct 12 '18 16:10 dbudihartono

any solution?

anjaneyulugulla avatar Mar 25 '19 14:03 anjaneyulugulla

any solution?

@dbudihartono udah ketemu gan?

ib-ganz avatar Sep 24 '19 09:09 ib-ganz

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!

haniefhan avatar Feb 19 '20 05:02 haniefhan

I have the same problem :(

arminamirinasab avatar Oct 30 '20 07:10 arminamirinasab