Yii import or include

I had a problem importing php files.

Why does it work:

include( Yii::getPathOfAlias( 'ext.payu.payU').'.php' ); 

but this is not so:

 Yii::import( 'ext.payu.payU'); 

?

payU.php file:

 include_once( dirname(__FILE__) . "/sdk/openpayu.php"); //this is a valid path class payU{ } 
+6
source share
2 answers

Try Yii::import('ext.payu.payU', true) , because by default a one-parameter call to the Yii::import() function means:

Hey, just add this path to the list of known aliases and don't require() now

and you need to do new payU() for this.

+9
source

Import works as follows: Open the directory and load the class into a php file; state: class name is the index of the file name.

Instead of Include, loads all classes in a php file

0
source

Source: https://habr.com/ru/post/924714/


All Articles