How to get the value of parameters in yii2 configuration file

WBOY
Release: 2016-07-06 13:54:04
Original
2944 people have browsed it

I want to put the appid of the WeChat public account into a custom parameter in a configuration file, and then it can be called in any controller. If it is modified, the place where it is called will be modified.

Reply content:

I want to put the appid of the WeChat public account into a custom parameter in a configuration file, and then it can be called in any controller. If it is modified, the place where it is called will be modified.

config/param.php

Yii:$app->params['key'] key is your parameter key name

First put the parameters into the params.php file in the config directory, as follows:

<code>return [
    'key' => 'value',
];</code>
Copy after login

Then, when quoting, use:

<code>\Yii::$app->params['key']</code>
Copy after login

Note that it is params, not param.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!