Welcome Guest, Not a member yet? Register   Sign In
Any idea why this array from config isn't "accessable"?
#1

[eluser]esset[/eluser]
Hey guys, I have a wierd issue. I'm not sure if I'm doing something wrong or whats going on.

In my config-file I have this:
Code:
$config['permissions']['create_user']        = "n";
    $config['permissions']['create_case']        = "n";
    $config['permissions']['can_assign_teams']    = "n";
    $config['permissions']['can_access_users']    = "n";


Then in my MODEL I'm doing this:
Code:
$permissions         = $this->config->item('permissions');
        
        foreach($permissions as $key => $value)
        {
            $field = $this->input->post($key, 'xss_clean|trim');
            if(isset($field)) $permissons[$key] = $field;
        }

        print_r($permissions);

If I POST a variable "create_user" with a value of "y" it doesn't stick to the array. The key "create_user" is still "n" in the print_r.

Even if I set it manually in the code like so:
Code:
$permissions['create_user'] = "y";
print_r($permissions);

the output is still "n" for that key in print_r and the array.



Any ideas why this is so? Am I accessing/setting the array wrong?

Thanks
#2

[eluser]Dennis Rasmussen[/eluser]
Try set the config item with the following:
Code:
$this->config->set_item('item_name', 'item_value');

Let me know if it works Smile
#3

[eluser]esset[/eluser]
The problem isn't the config item not being set. They are all there.

The problem is when I do

Code:
$permissions[$key] = "Foo";

The value "n" doesn't get overwritten. It's still "n" when I do the print_r.

Any ideas? Thanks so much
#4

[eluser]tomcode[/eluser]
You've got a typo (permissons instead of permissions) in Your code :
Code:
if(isset($field)) $permissons[$key] = $field;

Additionally, You're if clause evaluates always to true since $field is always set. If You want to check for empty, You could use :
Code:
if($field) $permissions[$key] = $field;
#5

[eluser]esset[/eluser]
Ah correct, thanks.

Problem is that it still doesn't work.

If I run $permissions['create_user'] = "Foo"; just before print_r($permissions); the value for "create_user" is still "n" in the output.
#6

[eluser]esset[/eluser]
I got it working.

I have no idea why it's behaving like this, but I added in: $permissions = array(); before fetching it from config and in some mysterious way it worked.

Thanks guys




Theme © iAndrew 2016 - Forum software by © MyBB