3

I have yet another weird annoying thing going on with Zend.

Basically, I have the following code after creating a user domain:

$this->auth = Zend_Auth::getInstance();
$this->view->user = $this->user = $this->auth->getIdentity();
$this->user->idSite = $idSite;
$this->user->urlSite = $urlSite;
$this->auth->getStorage()->write($this->user);

What FURIOUSLY annoys me is that the auth->getIdentity() just moments after that:

[idSite] => 0
[urlSite] => 

So from here it gets worse: If I REFRESH or if any of the other parameters of the form fail and send me to the SAME FORM, but WITHOUT TOUCHING THE ABOVE SCRIPT, the auth-getIdentity() correctly returns:

[idSite] => 2431
[urlSite] => exampledomain

Which means that the code is correct and working, BUT if the form is filled out correctly and everything adds up nicely, I redirect to the next step: $this->_redirect('nextstep'), and neither idSite or urlSite remain empty forever.

Why is this? Why?

Charles
  • 50,943
  • 13
  • 104
  • 142
John
  • 261
  • 1
  • 3
  • 16

2 Answers2

3

I've had the same issue and I think it is better to go via the route of using the session namespace functionality:

$oSession = new Zend_Session_Namespace('myStorage');
$oSession->foo = "bar";
$oSession->baz = 123;

And you can recover the data by:

$oSession = new Zend_Session_Namespace('myStorage');
$this->view->foo = $oSession->foo;

There are some more clues here: Zend_Auth the main message of which is that the storage of Zend_Auth data is actually just a namespace.

The default access to this would be similar to :

$oSession = new Zend_Session_Namespace('Zend_Auth');

Ian Lewis
  • 1,311
  • 13
  • 18
  • 1
    This is one year later and I'm constructing a different project. The same problems have led me down the same path and i have found your post again. This is THE solution. It solves everything, always works and it clean and pure in its implementation, especially when abstracted. – John Apr 13 '11 at 15:05
1

I also had trouble with Zend_Auth not writing to storage. However, after seeing the answer by Ian Lewis and your response I realised it was probably writing ok, but not reading. I had previously changed the 'name' setting in my session to my own namespace. Once I removed this and started using the default again my Zend_Auth worked fine.

Daniel Wood
  • 4,487
  • 3
  • 38
  • 36