How to load class in custom directory ?


i have custom directory:

> app > components > payments

–> paypal.php

–> transfer.php

for those files i use namespace: \app\components\payments

how to autoload that files in Yii2 ?

in Yii1 there is "import" feature that use to import custom directory.

If you’ve named classes correctly, you don’t need to load them manually.

hi @samdark thank you for your response.

i can not find "Yii::import()" in Yii2, so i did like here :

$code = 'paypal';

require_once \Yii::getAlias('@app/components/totals/' . $code .'.php');

So far it solved my problem. but i’m not sure if it the right way in Yii2.

As I said, if everything is correct you don’t need to do anything manually. Seems something’s wrong in your case. Either you’re loading a class from a namespace that’s unknown to autoloader or file name doesn’t match class name.

thanks it work without manually include class. just change the namespace and automatically loaded :)