2009-07-05 39 views
1

嗨我的问题与我的会议使用Zend Framework 1.7.6。节点不再存在Zend_Session的错误

当我尝试将数组存储到会话中时,存在问题,会话名称空间也存储其他用户数据。

我目前我的堆栈跟踪

 
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - 
... 

Error #2 session_start() [function.session-start]: Node no longer exists Array 

代码收到以下消息,我觉得这是示数是:

//now we add the user object to the session 
    $usersession = new Zend_Session_Namespace('userdata'); 
    $usersession->user = $user; 

    //we now get the users menu map   
    $menuMap = $this->processMenuMap($menuMapPath); 

    $usersession->menus = $menuMap; 

此错误才开始,因为试图添加的出现数组添加到会话名称空间。

任何想法可能导致节点不再存在Array消息?

非常感谢

回答

3

你们是不是要在会话中存储的数据相关的SimpleXML对象或别的东西的libxml?
这不起作用,因为在session_start()期间对象未被序列化时,底层DOM树未被恢复。改为存储xml文档(以字符串形式)。

您可以实现例如通过提供"magic functions" __sleep() and __wakeup()。但是__sleep()必须返回一个数组,其中包含要序列化的所有属性的名称。如果添加其他属性,则还必须更改该数组。这删除了一些automagic ...

但是,如果你的menumap类只有几个属性,它可能是适合你的。

<?php 
class MenuMap { 
    protected $simplexml = null; 
    protected $xmlstring = null; 

    public function __construct(SimpleXMLElement $x) { 
     $this->simplexml = $x; 
    } 

    public function __sleep() { 
     $this->xmlstring = $this->simplexml->asXML(); 
     return array('xmlstring'); 
    } 

    public function __wakeup() { 
     $this->simplexml = new SimpleXMLElement($this->xmlstring); 
     $this->xmlstring = null; 
    } 

    // ... 
} 
+0

我使用simplexml。我的菜单/站点地图存储在一个xml文件中,我尝试并将它们存储在一个存储到数组中的Menu对象中。有什么方法可以实现我想要做的? – 2009-07-05 16:40:00

1

您应该将XML字符串存储在会话中。或者,您可以围绕该XML字符串,要么一个包装类:

在这些方法中,您可以关注对象的状态。

+0

在这里实现Serializable当然比我的__sleep/__ wake示例更好。 – VolkerK 2009-07-06 23:00:16