Welcome Guest, Not a member yet? Register   Sign In
Get config item in array
#1

[eluser]Unknown[/eluser]
Hello.
I made a new config file where I put all my config variables, and because I may have a name confict I put my variable into array:
$config['mysite']['name'] = ...

I get this variable using:
Code:
$name = $this->config->item('mysite');
$name = $name['name'];

but this way is ugly. How to rewrite this part of code to get only 1 line of code?

Thanks.
#2

[eluser]Kamarg[/eluser]
Code:
$name = element('name', $this->config->item('mysite'));
#3

[eluser]leela[/eluser]
use config variable as $config['mysite'] = array('name' => 'some thing');

now you can use this directly as an array in the controller $this->config->item('mysite');

or config_item('mysite')


--
Leela Narasimha Reddy
#4

[eluser]Aken[/eluser]
It's helpful to prefix your variables to prevent name conflicts anyway. I'd personally just rename it to something that is unique.
#5

[eluser]vbsaltydog[/eluser]
Why not just do what the documentation says to do?

Quote:If you need to load multiple config files normally they will be merged into one master config array. Name collisions can occur, however, if you have identically named array indexes in different config files. To avoid collisions you can set the second parameter to TRUE and each config file will be stored in an array index corresponding to the name of the config file. Example:

// Stored in an array with this prototype: $this->config['blog_settings'] = $config
Code:
$this->config->load('blog_settings', TRUE);

Quote:// Retrieve a config item named site_name contained within the blog_settings array
Code:
$site_name = $this->config->item('site_name', 'blog_settings');

http://ellislab.com/codeigniter/user-gui...onfig.html




Theme © iAndrew 2016 - Forum software by © MyBB