1

私は次のようなsfuser/属性を持っています:

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:{}
}}

setAttribute( "mysetting"、 "val")を使用すると、例のshowのようにmysettingが保存されます。したがって、同じ答えが得られたので、setAttribute( "mysetting"、 "val"、15)を使用する必要はありません。

ノード15またはarrayBunchにアクセスするには、 setAttributeを使用してそこに値を入力するか、getAttributeを使用してそれらを取得するにはどうすればよいですか?

4

1 に答える 1

2

私はあなたが間違った方法でそれをしていると思います(パラメータについて)。

あなたがしたいことは:

  • と呼ばれる変数を追加しますval
  • 値で15
  • 名前空間内mysetting

しかし、あなたは間違った順序でパラメータを書きました。

コードを確認すると、パラメータは次のようになります。

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

だからあなたは試してみるべきです:

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

編集:( 申し訳ありませんが問題に気づいていませんでしたarrayBunch

arrayBunch値を編集する場合:

// 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);

編集

15namepsaceがデフォルトの属性であるため、jsonをよく見ると、属性全体を取得する必要がありますsymfony/user/sfUser/attributes。それで:

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

そして、いくつかの変更を適用したい場合:

// 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);
于 2012-08-06T10:29:19.580 に答える