S.M_Emamian
S.M_Emamian

Reputation: 17383

Fatal error: Class 'Predis\Client' not found

I'm using codeigniter framework. I want to use redis on my project.

to do this I find this library:

https://packagist.org/packages/predis/predis

I installed it with composer.

now I want to use it:

  $client = new Predis\Client();

but I got this message:

Message: Class 'Predis\Client' not found

I set up these configs:

$config['composer_autoload'] = '/vendor/autoload.php';
$config['composer_autoload'] = TRUE;

enter image description here

my OS is windows 7. somewhere says I should install redis on my windows because I'm using localhost. yeah?

updated enter image description here

Upvotes: 2

Views: 5372

Answers (1)

Tpojka
Tpojka

Reputation: 7111

Move composer.json, composer.lock and vendor inside application directory and leave $config['composer_autoload'] = '' empty. It is recommended since that way someone won't be allowed reading what external libraries/packages your application uses. Also APPPATH.'vendor' is default CI location (by docs).

If you for some reason want to have composer.json in publicly accessible location, try your existing configuration with this change:

$config['composer_autoload'] = FCPATH.'vendor/autoload.php';

Also, have you put

use Predis\Client as PredisClient;//for distinctive use of Client word in case of Guzzle, other libs, etc.

before controller class code? After that you can use it as

$client = new PredisClient();

Check if all of this works.

Upvotes: 4

Related Questions