How to troubleshoot Composer autoload in Codeigniter? - php

I am new to using Composer in Codeigniter and have read all I can to try and fix my issue, but are coming up short. The autoloader seems to to be autoloading? So here is where I am stuck:
I have installed a composer.
Required the MPDF package using composer require pdf/mpdf
I did that from the root of my project, so the vendor folder, as well as the composer.json file is on the root of my project
In my config/config.php file, I changed the composer_autoload value to
$config['composer_autoload'] = FCPATH . "/vendor/autoload.php";
Then I created a simple function in my default controller like this:
function m_pdf() {
$mpdf = new mPDF();
$mpdf->WriteHTML('Hello World');
$mpdf->Output();
}
But when I run it, I get an error: Message: Class 'mPDF' not found
I have tried moving everything to the application folder, and change the value in the config file to TRUE, I have tried calling the autoloader from the function itself, but no luck.
I feel I am missing something obvious. Maybe some dependencies. As I said, I am new to use the composer. There were some suggestions on the web about running php composer.phar but I get an error when I try and run that. Could that be it?

1) in namespace => use correct Mpdf class
If still not help => composer dump-autoload(reconfigure your composer classMap)
If dump-autoload not help =>
remove vendor directory
composer install

Related

Facing issue installing pug-php/pug-symfony on Symfony 2.8.26

I am facing an issue while installing pug-php/pug-symfony in Symfony 2.8.
I started with a fresh symfony installation and executed
composer require pug-php/pug-symfony
All the dependencies were fetched and downloaded and tyhe composer.json also got updated, however in the step of autoloader.php generation, it comes up with this error. (below image)
autoload.php issue when installing pug on symfony
To debug the issue, i tried executing
composer dump-autoload -o
and the same error pops up again.
Next, I tried something cheeky and created a new blank autoload.php file in the Symfony project directory root, and again executed composer update and composer dump-autoload, however, this time am getting this,
composer update issue (2)
Please help.
Your path is wrong currently it is stating that there is no autoload.php file in the directory C:\xampp\htdocs\demoSymfony\autoload.php. There should be a vendor directory where the autoload.php file is found. Can you update your question with the current Repository structure/hierarchy? That will probably give us more info to help you.
Straight from their docs: For libraries that specify autoload information, Composer generates a vendor/autoload.php file. You can simply include this file and start using the classes that those libraries provide without any extra work
https://getcomposer.org/doc/01-basic-usage.md#autoloading
We have solved this issue, you should now be able to install it with no such problem by following the README install process:
https://github.com/pug-php/pug-symfony#pug-symfony

Guzzle installation - Client Use

Forgive my ignorance but i've been struggling to get Guzzle to install in my project's folder.
I have installed Composer via it's .exe installer.
I have a composer.json file which contains the following:
{
"require": {
"guzzlehttp/guzzle": "~5.1"
} }
I can run 'composer update' in which it installs Guzzle.
However, it installs "Vendor" folder which has folders
'Guzzlehttp'-> 'guzzle' then is has 'build','src',tests' etc.
I want to use the Client object but the documentation says add:
'use GuzzleHttp\Client;' to the top of the PHP file but I don't actually have that file structure. Inside my guzzlehttp is just 'guzzle' or 'streams'folders.
Am I write in thinking Guzzle has not installed propperly? Or is there a different way to do it in Guzzle 5?
Many thanks for any help
You should include Composer's autoloader file which takes care of loading any Composer-installed library, the autoloader file is located in the vendor directory.
Use the following in your code :
// include Composer's autoloader
require "vendor/autoload.php";
// this should work just fine now
$resp = GuzzleHttp\get("http://stackoverflow.com");

Config php via parse.com through composer

I have tried to install php via composer and without composer in Parse. Guide for install php through paser.I followed the steps and procedure but its not working please let me know how to solve this problem.
The part you may be struggling with is installing the composer using this command:
php composer.phar install
Then 'ls' to see is you have a vendor directory.
Let me know how it works out.
You can use the autoload.php file included in the source code to include the SDK files easily. You can also use this tutorial to help you get started with the Parse PHP SDK without using Compose.
You need to do something like:
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'yyy', 'zzz');
Install Composer. Download Composer
Create new Project.
Create composer.json file with dependencies like
{
"require" : {
"parse/php-sdk":"1.1.*"
}
}
In the project folder open cmd and run the command composer install after that follow the parse quick start guide.
It works in my case.

Why my autoload.php of composer doesn't work?

I have a project, I use Composer and i import many thing by it... i require the autoload.php in my index (the root of project) and istead Slim, Mongo, Twig work very well. But when I call a class of Respect/Validation it doens't work; if I simply use Respect/Validation the error is:
Class 'Respect\Validation\Validator' not found in (path of file when i need it).
if I try to require also here the autoload.php the errors are:
**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)
**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)
Try using php composer dump-autoload. It may fix that problem.
If you are using a file (file.php) in a particular directory like this:
/app/controller/validation
and your vendor directory is in the base path of the project, you need to include the relative path to vendor directory:
../../../vendor/autoload.php
I did this.
i checked the file and permissions as always but everything looks ok. Then I open autoload.php and see ... oh! we have __DIR__ ofcourse.
I was doing this
require '../../vendor.autoload.php';
Changed to
require __DIR__.'../../vendor.autoload.php';
Not politically correct but got me by the frustrating waste of time for the moment.
ofcourse there are better alternatives to __DIR__ like using a BASE Path etc. But this worked for me.
I had the same issue with xampp. I installed composer and used:
composer create-project --stability=dev --prefer-dist yiisoft/yii2-app-basic D:\xampp\htdocs\newapp
My issue solved now.
I had the same problem and i solved it by using the last version of laravel, just try this code to create your project:
composer create-project laravel/laravel exampleProject --prefer-dist
this always uses the last version.
I solved simple re-run composer update from the project Root.
(my case was on Magento2, but the error and the path are the same)
In my case i simple forgot to change my working directory before running the command composer require cboden/ratchet in cmd this fixed it cd c:\path to project\ then composer require cboden/ratchet

Don't found a class php imported with composer [duplicate]

I have a project, I use Composer and i import many thing by it... i require the autoload.php in my index (the root of project) and istead Slim, Mongo, Twig work very well. But when I call a class of Respect/Validation it doens't work; if I simply use Respect/Validation the error is:
Class 'Respect\Validation\Validator' not found in (path of file when i need it).
if I try to require also here the autoload.php the errors are:
**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)
**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)
Try using php composer dump-autoload. It may fix that problem.
If you are using a file (file.php) in a particular directory like this:
/app/controller/validation
and your vendor directory is in the base path of the project, you need to include the relative path to vendor directory:
../../../vendor/autoload.php
I did this.
i checked the file and permissions as always but everything looks ok. Then I open autoload.php and see ... oh! we have __DIR__ ofcourse.
I was doing this
require '../../vendor.autoload.php';
Changed to
require __DIR__.'../../vendor.autoload.php';
Not politically correct but got me by the frustrating waste of time for the moment.
ofcourse there are better alternatives to __DIR__ like using a BASE Path etc. But this worked for me.
I had the same issue with xampp. I installed composer and used:
composer create-project --stability=dev --prefer-dist yiisoft/yii2-app-basic D:\xampp\htdocs\newapp
My issue solved now.
I had the same problem and i solved it by using the last version of laravel, just try this code to create your project:
composer create-project laravel/laravel exampleProject --prefer-dist
this always uses the last version.
I solved simple re-run composer update from the project Root.
(my case was on Magento2, but the error and the path are the same)
In my case i simple forgot to change my working directory before running the command composer require cboden/ratchet in cmd this fixed it cd c:\path to project\ then composer require cboden/ratchet

Categories