Zend_Auth fails to write to storage

谁说我不能喝 提交于 2019-12-10 19:02:00

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/1379597/zend-auth-fails-to-write-to-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!