php教程

超轻量级php框架startmvc

Yii框架参数配置文件params用法实例分析

更新时间:2020-04-08 02:16:00 作者:startmvc
本文实例讲述了Yii参数配置文件params用法。分享给大家供大家参考,具体如下:1.标题的调

本文实例讲述了Yii参数配置文件params用法。分享给大家供大家参考,具体如下:

1.标题的调用

1.1设置


<?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调用

这个只是简单的调用参数的方法


<title><?=Yii::$app->params['title'];?></title>

2.URL的拼凑

2.1设置


<?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 调用


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:


<?= $this->context->id ?>
Yii 参数配置文件 params