'components' => [
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/basic'],
'baseUrl' => '@web/themes/basic',
],
],
],
$pathMap=[
'@app/a' => '@app/aaa',
'@app/b' => '@app/bbb',
'@app/c' => [
'@app/ccc/xxx',
'@app/ccc/yyy',
],
];
$pathMap=[
'@app/c' => [
'@app/ccc/blank',
'@app/ccc/default',
],
];
'pathMap' =>[
'@app/views' => [
'@app/themes/blank',
'@app/themes/default',
],
'@app/modules' => '@app/themes/default/modules',
'@app/widgets' => '@app/themes/default/widgets'
],
public function init()
{
parent::init();
//如果没有设置$pathMap映射,则使用$basePath,
if (empty($this->pathMap)) {
/*
* 如果$basePath也没有设置,则出异常。
* 也就是说 $pathMap和$basePath至少要设置一个,如果两个都设置了,优先使用$pathMap
*/
if (($basePath = $this->getBasePath()) === null) {
throw new InvalidConfigException('The "basePath" property must be set.');
}
//设置当前模块的路径和$basePath的映射关系
$this->pathMap = [Yii::$app->getBasePath() => [$basePath]];
}
}
//这个就是按照 $pathMap中的定义的映射关系来对$path进行替换字符串的
public function applyTo($path)
{
//对路径中的"/"、“\”进行统一替换
$path = FileHelper::normalizePath($path);
foreach ($this->pathMap as $from => $tos) {
//映射数组中的来源(旧值)
$from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
//如果在$path中有可替换的旧值
if (strpos($path, $from) === 0) {
$n = strlen($from);
//对目标值循环,
foreach ((array) $tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
//把$path中的$from替换为$to
$file = $to . substr($path, $n);
//如果是文件,直接返回
if (is_file($file)) {
return $file;
}
}
}
}
return $path;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有