Zend_Session 节点不再存在错误 [英] Node no longer exists error with Zend_Session

查看:54
本文介绍了Zend_Session 节点不再存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Zend Framework 1.7.6 时遇到问题.

当我尝试将数组存储到会话时存在问题,会话命名空间还存储其他用户数据.

我目前在堆栈跟踪中收到以下消息

<前>致命错误:未捕获的异常 'Zend_Session_Exception' 带有消息 'Zend_Session::start() -...错误 #2 session_start() [function.session-start]:节点不再存在数组

我认为这是错误的代码是:

//现在我们将用户对象添加到会话中$usersession = new Zend_Session_Namespace('userdata');$usersession->user = $user;//我们现在得到用户菜单映射$menuMap = $this->processMenuMap($menuMapPath);$usersession->menus = $menuMap;

自从尝试将数组添加到会话命名空间后,此错误才开始出现.

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

非常感谢

解决方案

您是否尝试在会话数据中存储 SimpleXML 对象或其他与 libxml 相关的内容?
这是行不通的,因为在 session_start() 期间对对象进行反序列化时,底层 DOM 树不会恢复.改为存储 xml 文档(作为字符串).

你可以做到这一点,例如通过提供 "魔法函数" __sleep()__wakeup().但是 __sleep() 必须返回一个数组,其中包含要序列化的所有属性的名称.如果添加另一个属性,则还必须更改该数组.这消除了一些自动魔术...

但是如果您的 menumap 类只有几个属性,那么它可能对您来说是可行的.

simplexml = $x;}公共函数 __sleep() {$this->xmlstring = $this->simplexml->asXML();返回数组('xmlstring');}公共函数 __wakeup() {$this->simplexml = new SimpleXMLElement($this->xmlstring);$this->xmlstring = null;}//...}

Hi I am having issues with my my sessions using Zend Framework 1.7.6.

The problem exists when I try and store an array to the session, the session namespace also stores other userdata.

I am currently getting the following message in my stacktrace

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

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

The code where I think this is erroring is:

//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;

This error has only started to appear since trying to add an array to the session namespace.

Any ideas what could be causing the Node no longer exists Array message?

Many thanks

解决方案

Are you trying to store a SimpleXML object or something else libxml related in the session data?
That doesn't work because the underlying DOM tree isn't restored when the objects are unserialized during session_start(). Store the xml document (as string) instead.

You can achieve that e.g. by providing the "magic functions" __sleep() and __wakeup(). But __sleep() has to return an array with the names of all properties that are to be serialized. If you add another property you also have to change that array. That removes some of the automagic...

But if your menumap class has only a few properties it might be feasible for you.

<?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;
    }

    // ...
}

这篇关于Zend_Session 节点不再存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆