1

Trying to import a class while in config/main.php (before the Yii configuration is returned):

 //class LanguageSettings is placed directly in protected/components/LanguageSettings.php
 Yii::import('application.components.*');
 LanguageSettings::currentLanguage();

causes that fatal error:

 Fatal error: Uncaught exception 'CException' with message 
 'Alias "application.components.*" is invalid. Make sure it points to an existing 
 directory or file.' in C:\xampp\htdocs\yii\framework\YiiBase.php:

Why ? Can Yii resolve the alias correctly before importing the configuration array ?

Sebastian
  • 709
  • 1
  • 8
  • 15

1 Answers1

1

Sorry, I do not think it will work because the basePath has not been set yet, therefore Yii cannot calculate where application.components.* is referring to.

stratosgear
  • 942
  • 1
  • 16
  • 37
  • Thank you for the answer. Is there any other way the path can be imported (manually)? – Sebastian Dec 07 '11 at 14:42
  • Well, since usually basePath (in config/main.php) is defined as dirname(__FILE__).DIRECTORY_SEPARATOR.'..' you can define it in a variable ($myBasePath) at the top of main.php and then manually do import_once($myBasePath . '/components/myComponent.php') bypassing the autoimport functionality of Yii. Kinda hacky, though... – stratosgear Dec 07 '11 at 19:13
  • Hacky but helpful. Thank you ! ps. import_once = include / require_once. – Sebastian Dec 12 '11 at 15:56