h3rm
June 20, 2017, 3:51pm
1
Hello,
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.
samdark
(Alexander Makarov)
June 20, 2017, 9:35pm
2
If you’ve named classes correctly, you don’t need to load them manually.
h3rm
June 21, 2017, 3:05am
3
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.
samdark
(Alexander Makarov)
June 23, 2017, 7:42pm
4
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.
h3rm
June 24, 2017, 5:17pm
5
thanks it work without manually include class. just change the namespace and automatically loaded