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

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

WBOY
WBOYOriginal
2016-06-13 12:10:091264browse

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 />

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


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

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