diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index b3803cb..55258ee 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -222,6 +222,18 @@ abstract class Application extends Module } /** + * Sets the root directory of the applicaition and the @app alias. + * This method can only be invoked at the beginning of the constructor. + * @param string $path the root directory of the application. + * @throws InvalidParamException if the directory does not exist. + */ + public function setBasePath($path) + { + parent::setBasePath($path); + Yii::setAlias('@app', $this->getBasePath()); + } + + /** * Runs the application. * This is the main entrance of an application. * @return integer the exit status (0 means normal, non-zero values mean abnormal) diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index 8e62d0a..a03fd83 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -217,9 +217,6 @@ abstract class Module extends Component $p = realpath($path); if ($p !== false && is_dir($p)) { $this->_basePath = $p; - if ($this instanceof Application) { - Yii::setAlias('@app', $p); - } } else { throw new InvalidParamException("The directory does not exist: $path"); }