yii\base\Module::setBasePath PHP Method

setBasePath() public method

This method can only be invoked at the beginning of the constructor.
public setBasePath ( string $path )
$path string the root directory of the module. This can be either a directory name or a path alias.
    public function setBasePath($path)
    {
        $path = Yii::getAlias($path);
        $p = strncmp($path, 'phar://', 7) === 0 ? $path : realpath($path);
        if ($p !== false && is_dir($p)) {
            $this->_basePath = $p;
        } else {
            throw new InvalidParamException("The directory does not exist: {$path}");
        }
    }

Usage Example

Example #1
0
 /**
  * Sets the root directory of the application 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.
  * @property string 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());
 }