Home >Backend Development >PHP Tutorial >How to get the value of parameters in yii2 configuration file

How to get the value of parameters in yii2 configuration file

WBOY
WBOYOriginal
2016-07-06 13:54:042997browse

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>

Then, when quoting, use:

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

Note that it is params, not param.

Statement:
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