1
votes

I have a sfuser/attributes looking like this:

session:
 symfony/user/sfUser/attributes: {
    symfony/user/sfUser/attributes:{
        15:{
            Telefon:'+304994994994',
            option:'15',
            rules:'12',
            arrayBunch:[{
              this: 'da',
              that: "where"
            }]
        },
        17:{...},
        mysetting: "val"
    },
    sfGuardSecurityUser:{},
    admin_module:{},
    sfGuardUserSwitcher:{}
}}

When i use setAttribute("mysetting", "val") they stores mysetting like show on my example. It is therefore unnecessary to use setAttribute("mysetting", "val", 15) because i got the same answer.

How can i access the nodes 15 or arrayBunch an use setAttribute to input a value there or getAttribute to get'em?

1
Are you sure about setAttributes? Because sfUser doesn't have setAttributes but has a setAttribute.j0k
Sorry you are right! it's setAttribute i edit my post!!3logy

1 Answers

2
votes

I think you are doing it in a wrong way (about parameters).

What you want to do is:

  • add a variable called val
  • with the value 15
  • in the namespace mysetting.

But, you have written parameters in a wrong order.

If you check the code, parameters are :

public function setAttribute($name, $value, $ns = null)

So you should try:

->setAttribute('val', 15, 'mysetting');

Edit: (sorry didn't notice the arrayBunch problem)

If you want to edit the arrayBunch value:

// retrieve the current value
$arrayBunch = $this->getUser()->getAttribute("arrayBunch", array(), 15);

// made some modification
$arrayBunch['toto'] = 'titi';
$arrayBunch['this'] = 'do';

// put back the modification
$this->getUser()->setAttribute("arrayBunch", $arrayBunch, 15);

Edit:

With a closer look to your json, you should retrieve the whole attribute 15, since the namepsace is the default one: symfony/user/sfUser/attributes. So:

$attribute15 = $this->getUser()->getAttribute(15);
$arrayBunch  = $attribute15['arrayBunch'];

And if you want to apply some changes:

// update arrayBunch
$arrayBunch['this'] = 'dada';
// do not forget to re-add modified arraybBunch to the whole variable
$attribute15['arrayBunch'] = $arrayBunch

// and if you want to add a value
$attribute15['mysetting'] = 'val';

// then, save every thing to the session again
$this->getUser()->setAttribute(15, $attribute15);