Yii Framework Forum: How to load configuration set in config/main.php? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to load configuration set in config/main.php? Rate Topic: -----

#1 User is offline   liang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-June 10

Posted 19 July 2010 - 07:47 PM

If I added some key-value pairs in the returned array in config/main.php, how can I load value with a given key?
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 20 July 2010 - 02:27 AM

Set the configuration in 'param' (like adminEmail in the default skeleton)

so in configMain:
	'params'=>array(
		// this is used in contact page
		'adminEmail'=>'webmaster@example.com',
		'myParam'=>'myValue',
	),


In your code, wherever you need:

$param=Yii::app()->params['myParam'];

0

#3 User is offline   liang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-June 10

Posted 20 July 2010 - 12:29 PM

Thank you! I read through the definitive guide and could not find the answer. So usually how to find the answer for this kind of questions?

View Postzaccaria, on 20 July 2010 - 02:27 AM, said:

Set the configuration in 'param' (like adminEmail in the default skeleton)

so in configMain:
	'params'=>array(
		// this is used in contact page
		'adminEmail'=>'webmaster@example.com',
		'myParam'=>'myValue',
	),


In your code, wherever you need:

$param=Yii::app()->params['myParam'];


0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 21 July 2010 - 01:59 AM

Posting in the forum.. :lol:


I am jocking. Just keep in mind that all is defined in main.conf (and all that belongs to CWebApplication) can be accessed in any part of code with Yii::app()
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users