Yii Framework Parameter Configuration File params Usage Example Analysis
- 2021-12-21 04:18:35
- OfStack
This article illustrates the use of the Yii parameter configuration file params. Share it for your reference, as follows:
1. Call of the title
1.1 Settings
<?php
return [
'title' => ' Book store ',
"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 Call
This is just a simple method to call parameters
<title><?=Yii::$app->params['title'];?></title>
2. The patchwork of URL
2.1 Settings
<?php
return [
'title' => ' Programming mall ',
'domain' => [
'www' => 'http://book_my.aa.test',
'm' => 'http://book_my.aa.test/m',
'web' => 'http://book_my.aa.test/web'
],
2.2 Call
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. Load sequence
The back will overwrite the front
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:
<?= $this->context->id ?>
More readers interested in Yii can check the topics of this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent Development Framework of php", "Basic Tutorial for Introduction to smarty Template", "Introduction to php Object-Oriented Programming", "Summary of Usage of php String (string)", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
Hope that this article is based on the framework of Yii PHP programming help.