php - Symfony2: store and retrieve array in session -
i new symfony2 & using symfony 2.5. following official symfony documentation guidance on session. store , retrive array session, following this official documentation.
problem background
when user logs in , enters website front page, start new session, , store information using following code.
$sessiondata = array( 'unit' => $unit, 'client' => $client, 'group' => $group, ); $session = new session(); $session->set('fw', $sessiondata);
when print_r
session info, gives me following output, expected.
array ( [fw] => array ( [unit] => shoes [client] => nike [group] => north ) )
problem 1
now when want add further data array, follow same symfony documentation given here http://symfony.com/doc/current/components/http_foundation/sessions.html#attributes , following.
$this->get("session")->set('fw/storeid', $storeid);
as per documentation new store id detail should stored in session key=>value pair inside fw array. however, saves is. when print_r
, output get.
array ( [fw] => array ( [unit] => shoes [client] => bata [group] => north ) [fw/storeid] => abc1 )
am doing wrong? there different way store data in array in session?
problem 2
from above session, when want fetch data, docs says. $this->get("session")->get('fw/unit');
. however, gives me undefined index error. once again, correct way fetch data array within session?
are there mode detailed examples available anywhere?
as workaround follows , (which docs says can avoid):
$sessiondata = $this->get("session")->get('fw'); $sessiondata['storeid'] = $storeid; $this->get("session")->set('fw', $sessiondata);
Comments
Post a Comment