PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 7, 2022

[FIXED] Troubleshooting composer: classes not autoloading with CodeIgniter 3

 January 07, 2022     autoload, codeigniter, composer-php, php     No comments   

Issue

Problem

I am trying to use the PayPal Checkout REST SDK which requires the PayPal library to be autoloaded through composer. I have gone through the steps to enable Composer in CodeIgniter 3 but when I go to my controller where I am autoloading the PayPal\Rest\ApiContext class I get the following error:

Fatal error: Class 'PayPal\Rest\ApiContext' not found in C:\xampp\htdocs\php\toucan-talk\App\modules\paypal\controllers\Paypal.php on line 15

What I have so far

Here is my composer.json file

{
    "require": {
        "paypal/rest-api-sdk-php" : "*"
    }
}

I have set $config['composer_autoload'] = TRUE; in my config.php file.

Here is my controller

<?php

use PayPal\Rest\ApiContext;

class Paypal extends MX_Controller
{
    public function __construct()
    {
        $api = new ApiContext(

        );
        var_dump($api);
    }

}

Question

How do I troubleshoot composer and its autoloader so that I can pinpoint where the autoload process is failing.


Solution

Well here is the solution: in config.php instead of setting...

$config['composer_autoload'] = TRUE; 

You need to put

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

however I am still not certain why this works as opposed to the original documentations recommendation. Bit of a headache really.



Answered By - Jethro Hazelhurst
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing