Search code examples
phpyiiimportdir

how to import dir from outside the application in Yii?


I have a Yii webapp named A, and a second webapp named B that is inside A, I want to import A/protected/vendors/ in some B controllers, so I want to write in the controller something like:

Yii::import('/../application.vendors.*');

how I can do that ?


Solution

  • Set a path alias (to webapp A) on the top of your config file of webapp B (protected/config/main.php) for example:

    Yii::setPathOfAlias('absolutePathToWebAppA', '/home/user/domains/site.com/public_html');
    

    And in your controller in webapp B:

    Yii::import('absolutePathToWebAppA.protected.vendors.*');