Zend_Session_Namespace not working as expected
After creating a namespace, if I try to add a value to it, the variable has the particular value, but not the session with the namespace. But, if I create some variable, that is a key for an array, and add the value to it, it is saved to the session. To illustrate my point:
public $submitUser;
public function init ()
{
$this->submitUser = new Zend_Session_Namespace('submitUser');
Zend_Session::rememberMe(60*60*24*7);
}
public function selectUserAccount ($username)
{
$returnArray = array(
'name' => 'Man',
'surname' => 'With a surname',
'username' => $username
);
$this->submitUser->user = $returnArray;
}
Inserts into the session
'submitUser' =>
array
开发者_JAVA技巧 'user' =>
array
'name' => string 'Man' (length=3)
'surname' => string 'With a Surname' (length=14)
'username' => string 'jpeiseni' (length=8)
But
public function selectUserAccount ($username)
{
$returnArray = array(
'name' => 'Man',
'surname' => 'With a Surname',
'username' => $username
);
$this->submitUser = $returnArray;
}
Doesn't set the variables in the session
This is a small nuisance, that I can probably live with, but I would like to know if there is a reason not to allow the namaspace to have a value for it self, or am I missing something?
Yes this makes sense, what you're effectively doing is this:
$this->submitUser = new Zend_Session_Namespace('submitUser');
$this->submitUser = $returnArray;
so you create an instance of Zend_Session_Namespace and then you replace it with a completely different variable.
Perhaps something like this would make more sense (depending on what this code is for):
$this->submit = new Zend_Session_Namespace('submit');
$this->submit->user = $returnArray;
try this:
public function selectUserAccount ($username)
{
$returnArray = array(
'name' => 'Man',
'surname' => 'With a Surname',
'username' => $username
);
$this->submitUser->applySet('array_merge', $returnArray);
}
精彩评论