Yii2学习笔记二十一:Yii2 别名(Aliases)使用
一、config文件中配置(不是放在components中):
'aliases'=>[ '@home'=>'www.qinimai.com' ],
二、bootstrap.php文件中配置:
Yii::setAlias('@home', 'www');
三、获取Yii2 别名(Aliases):
Yii::getetAlias('@web');
四、Yii2 预定义的别名(Aliases):
@yii, BaseYii.php 文件所在的目录(也被称为框架安装目录) @app, 当前运行的应用 yii\base\Application::basePath @runtime, 当前运行的应用的 yii\base\Application::runtimePath. Defaults to @app/runtime. @webroot, the Web root directory of the currently running Web application. It is determined based on the directory containing the entry script. @web,the base URL of the currently running Web application. It has the same value as yii\web\Request::baseUrl. @vendor,yii\base\Application::vendorPath. Defaults to @app/vendor. @bower, the root directory that contains bower packages. Defaults to @vendor/bower. @npm, the root directory that contains npm packages. Defaults to @vendor/npm. @yii 别名是在入口脚本里包含 Yii.php 文件时定义的, 其他的别名都是在配置应用的时候, 于应用的构造方法内定义的。
文章
总共 0 条评论