Simple Classmap Yii2

There must be a simple way to require a class in Yii2, but I’ve yet to get it to run. I’m sure it’s a simple syntax issue.

In Yii 1 this ran fine:



Now that I’ve upgraded to Yii2 and installed Stripe via composer this:



And this:

Yii::$classMap['Stripe'] = '../vendor/stripe/stripe-php/lib/Stripe.php';


Result in this error:

PHP Fatal Error – yii\base\ErrorException

Class 'app\controllers\Stripe' not found

Note: The Stripe Library is not PSR-4 standard and Composer has loaded all it’s files in the autoload_classmap.php file. How do I call the stripe classes from here:

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));

$baseDir = dirname($vendorDir);

return array(

    'Stripe' => $vendorDir . '/stripe/stripe-php/lib/Stripe/Stripe.php',

    'Stripe_Account' => $vendorDir . '/stripe/stripe-php/lib/Stripe/Account.php',

    'Stripe_ApiConnectionError' => $vendorDir . '/stripe/stripe-php/lib/Stripe/ApiConnectionError.php',

    // Edited to save forum space


Walked away for a minute and solved the issue. I added the classmap into the before action then added it to use like so:

use Stripe;

use Stripe_Charge;

class SiteController extends Controller


	public function beforeAction($action)


		Yii::$classMap['Stripe'] = '../vendor/stripe/stripe-php/lib/Stripe.php';

		Yii::$classMap['Stripe_Charge'] = '../vendor/stripe/stripe-php/lib/Stripe/Charge.php';

		return parent::beforeAction($action);



This is still not ideal as I have to include every class and not just Stripe.php

There must be a better way to handle this without forking Stripe and adding namespaces.