本文实例讲述了Yii参数配置文件params用法。分享给大家供大家参考,具体如下:
1.标题的调用
1.1设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<?php
return [
'title' => '图书商城' ,
"domain" => [
'www' => 'http://super.nat300.top/' ,
'm' => 'http://super.nat300.top/m' ,
'web' => 'http://super.nat300.top/web' ,
'weixin' => 'http://super.nat300.top/weixin' ,
],
"upload" => [
'avatar' => "/uploads/avatar" ,
'brand' => "/uploads/brand" ,
'book' => "/uploads/book" ,
],
"weixin" => [
"appid" => 'wxc01ba9b834be5023' ,
"sk" => 'da1e24dd41859f769b23c089f827268c' ,
"token" => 'tomalang689' ,
"aeskey" => 'P6PaB6bPrRzKkva5lq6kHWtYkOOlVhYq4fh1iR7LMKB' ,
'pay' => [
'key' => '' ,
'mch_id' => '' ,
'notify_url' => [
'm' => '/pay/callback'
]
]
]
];
|
1.2调用
这个只是简单的调用参数的方法
1
|
<title><?=Yii:: $app ->params[ 'title' ];?></title>
|
2.URL的拼凑
2.1设置
1
2
3
4
5
6
7
8
|
<?php
return [
'title' => '编程商城' ,
'domain' => [
'www' => 'http://book_my.aa.test' ,
'm' => 'http://book_my.aa.test/m' ,
'web' => 'http://book_my.aa.test/web'
],
|
2.2 调用
1
2
3
4
5
|
public static function buildMUrl( $path , $params = [] ){
$domain_config = \Yii:: $app ->params[ 'domain' ];
$path = Url::toRoute( array_merge ([ $path ], $params ));
return $domain_config [ 'm' ] . $path ;
}
|
3.加载顺序
后面的会覆盖前面的
1、common/config/params.php
2、common/config/params-local.php
3、frontend/config/params.php
4、frontend/config/params-local.php
The controller ID is:
1
|
<?= $this ->context->id ?>
|
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
原文链接:https://blog.csdn.net/fujian9544/article/details/89204096