Home > Backend Development > PHP Tutorial > yii的如何自定义一个全局的配置项

yii的如何自定义一个全局的配置项

WBOY
Release: 2016-06-13 12:10:09
Original
1285 people have browsed it

yii的怎么自定义一个全局的配置项?
各位大大,刚刚开始使用yii
我想自定义一个全局的配置项,类似与.net中的web.config中配置的那样
像这样访问:Yii::app()->myconfig
可以这样定义吗?该怎么搞?


------解决思路----------------------
在main配置文件里
有个params 的键的。写在里面就行了。
然后在controller
$this->params['你的key']
------解决思路----------------------
楼上正解

比较推荐做法是在/config/main.php里的最下面,默认应该是

<br />'params' => array(<br />    'adminEmail' => [email&#160;protected]',<br />),<br />
Copy after login

改为
<br />'params' => require('params.php'),<br />
Copy after login


然后在/config里建一个params.php
<br />return array(<br />    'adminEmail' => [email&#160;protected]',<br />);<br />
Copy after login

Related labels:
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