Home >Backend Development >PHP Tutorial >Yii2如果获取config/web.php配置的值?

Yii2如果获取config/web.php配置的值?

WBOY
WBOYOriginal
2016-06-06 20:37:32850browse

我在config文件夹下面新增几个配置文件,那我在controller里该如何获取,翻了手册好久都没找到相应的获取方法!
配置文件:

<code>php</code><code>return [
    'version' => '1.0.1',
    'category-map' => [
        1 => '样式1',
        2 => '样式2',
        3 => '样式3',
        4 => '样式4',
        5 => '样式5',
        6 => '样式6'
    ]
];
</code>

回复内容:

我在config文件夹下面新增几个配置文件,那我在controller里该如何获取,翻了手册好久都没找到相应的获取方法!
配置文件:

<code>php</code><code>return [
    'version' => '1.0.1',
    'category-map' => [
        1 => '样式1',
        2 => '样式2',
        3 => '样式3',
        4 => '样式4',
        5 => '样式5',
        6 => '样式6'
    ]
];
</code>

配置在 @app/config/params.php 里, 该文件已经包含在 @app/config/web.php 里的 params 下。
官网文档

楼上说得对,配置在@app/config/params.php里,读取方式为Yii::$app->params['paramsName']
比如Yii::$app->params['sitename']

自定义的东西还是配置到params数组中比较好

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