Welcome Guest, Not a member yet? Register   Sign In
Setting a Config Item
#1

(This post was last modified: 11-28-2016, 05:18 PM by mla.)

Hello
Is it possible to set a value into an item loaded from a config file?

I read into the manual the page about "Config Class"
Expecially about "set_item" function

But which is the syntax for 'item_name' in case item is loaded from a config file?

Example:

In my controller:


PHP Code:
    $this->load->library(array('ion_auth'));
...
    //get 'identity' value from loaded config file
    $id_type $this->config->item('identity''ion_auth');
...
    $id_type 'new_value';
...
    //set 'new_value' to 'identity' config item
    $this->config->set_item('identity'$id_type) ; 

In this case, I set 'new_value' into config array, but NOT in "ion_auth" occurrence...
Is it possible to do this?
Thanks
Reply
#2

As you have realized Ion auth loads config items into its own config key using this scheme

PHP Code:
$this->load->config('ion_auth'TRUE); 

What that means is that $config['ion_auth'] will hold an array of the contents of application/config/ion_auth.php

So to set the identity key this ought to work

PHP Code:
$config['ion_auth'] ['identity'] = 'new_value'

Or this amounts to the exact same thing only it requires more typing.

PHP Code:
$ion_auth_config $this->config->item('ion_auth');
$ion_auth_config ['identity'] = 'new_value'
Reply
#3

(This post was last modified: 11-29-2016, 06:22 AM by mla.)

With:


PHP Code:
$config['ion_auth'] ['identity'] = 'new_value'


I initialize $config array; but it isn't the same array where original configuration ion_auth was loaded...

If I try:


PHP Code:
var_dump($config); 


I have:

array(1) { ["ion_auth"]=> array(1) { ["identity"]=> string(9) "new_value" } }

If I try:


PHP Code:
var_dump($this->config); 


I see the original value, as loaded from file...

object(CI_Config)#3 (3) {

["config"]=> &array(...)
{
    ["ion_auth"]=> array(...)
        {  ["default_rounds"]=> int(8)
            ["identity"]=> string(5) "email"
            ["min_password_length"]=> int(8)
        }
}
}
Reply
#4

Doh!

That's what I get for responding when I should have gone to sleep.

This line

PHP Code:
$config['ion_auth'] ['identity'] = 'new_value'

Should have been

PHP Code:
$this->config->config['ion_auth'] ['identity'] = 'new_value'
Reply
#5

Ok. Many thanks.
This is th correct syntax for configuration parameters 'item_name' loaded from file 'file_name':


PHP Code:
$this->config->config['file_name'] ['item_name'] = 'new_value'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB