![]() |
Class not found - 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: Class not found (/showthread.php?tid=79257) |
Class not found - richb201 - 05-18-2021 I am still trying to install the sendpulse API. I finally got Composer to install it correctly and it created a file called /vendor/sendpulse/rest-api/ApiClient.php When I try to initialize it with this call: $SPApiClient = new ApiClient($_SESSION['sendpulse_API_USER_ID'], $_SESSION['sendpulse_SECRET'], new FileStorage()); I get this exception: Class 'Sendpulse\RestApi\ApiClient' not found. Now it seems clear to me (but not to the vendor) that /vendor/sendpulse/rest-api/ApiClient and Sendpulse\RestApi\ApiClient are in two different directories. I tried $SPApiClient = new vendor/sendpulse/rest-api/ApiClient($_SESSION['sendpulse_API_USER_ID'], $_SESSION['sendpulse_SECRET'], new FileStorage()); but I get this error: Class 'vendor' not found. So there must be someplace else where the path to the class is defined? RE: Class not found - iRedds - 05-18-2021 Is Composer autoloading included in your code? RE: Class not found - richb201 - 05-19-2021 Yes. I have require 'vendor/autoload.php'; at the top of the module. I just noticed that these two lines also appear in the module: use Sendpulse\RestApi\ApiClient; use Sendpulse\RestApi\Storage\FileStorage; As I said above the actual php files were installed by composer at /opt/docker-substantiator2/vendor/sendpulse/rest-api/src/ApiClient.php /opt/docker-substantiator2/vendor/sendpulse/rest-api/src/Storage/FileStorage.php Do I need to even have a use statement? RE: Class not found - iRedds - 05-19-2021 Yes, it is needed. There are two options for calling a class in a namespace. 1 use Sendpulse\RestApi\ApiClient; new ApiClient(); 2 new \Sendpulse\RestApi\ApiClient(); The result will be the same. Error "Class 'Sendpulse\RestApi\ApiClient' not found." means that the script cannot determine the location of the class. There are three possible reasons: 1. The composer is not included 2. The library is not installed 3. The library is not installed correctly / the composer has not indexed the library in the boot files. In the third case, you can try reindexing 'composer dump-autoload' or reinstalling the library. If the installation and/or indexing was successful, then an entry about the path to the library should appear in the vendor/composer/autoload_psr4.php file. RE: Class not found - richb201 - 05-19-2021 Thanks. I am using version 2 above. I still get Class 'ApiClient' not found. I then checked psr4 return array( 'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Intl\\Idn\\' => array($vendorDir . '/symfony/polyfill-intl-idn'), 'Sendpulse\\RestApi\\' => array($vendorDir . '/sendpulse/rest-api/src'), <<< it is right here 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'), 'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'), 'Http\\Client\\' => array($vendorDir . '/php-http/httplug/src'), 'Http\\Adapter\\Guzzle6\\' => array($vendorDir . '/php-http/guzzle6-adapter/src'), 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), ); I think the install was OK. I have done it at least 3 times. How can I check if the library is installed? Should I try reindexing or am I wasting my time? RE: Class not found - iRedds - 05-19-2021 The library you need is listed, so the installation is successful and no reindexing is needed. Everything seems to be fine. I do not even know now what could be the reason. Can you create an instance of the class of any other library installed through the composer? RE: Class not found - paulbalandan - 05-19-2021 Are you using CodeIgniter 3? If so, did you check your Code: application/config/config.php PHP Code: $config['composer_autoload'] = FCPATH . 'vendor/autoload.php'; RE: Class not found - richb201 - 05-19-2021 This is what I have: $config['composer_autoload'] = FCPATH . 'vendor/autoload.php'; //for ubuntu same! I sure hope the vendor is going to figure this out. |