简体   繁体   English

zend会话在课堂上不起作用

[英]zend session not working in class

I am using zend session, it workssetting up on the index page and if i use jquery's and check any session data. 我正在使用zend会话,它可以在索引页面上进行设置,如果我使用jquery并检查任何会话数据。 how ever within my class the session is empty? 在我的班级里,会议是怎么空的?

index.php index.php

$usersession = new Zend_Session_Namespace();
$usersession->surveyType = array("2D","3D");
$usersession->surveyTypeSelect = 'all';

file i use for jquery 我用于jquery的文件

$session = new Zend_Session_Namespace();
$log = $session->log;
$cache = $session->cache;
$surveyType = $session->surveyType;
$surveyTypeSelect = $session->surveyTypeSelect;

my class 我的课

$seismicLibrary = new Spectrum_Seismic_Library();

Any function within this class returns empty values for my saved session data. 此类中的任何函数都会为我保存的会话数据返回空值。

public function getAllSurveysByRegionId($regionId, $published = false) {
        //'Default'
        $session = new Zend_Session_Namespace();
        $log = $session->log;
        /*foreach ($session as $index => $value) {
            $log->debug(print_r("aNamespace->$index = '$value';\n",true));
        }*/
        $surveyType = $session->surveyType;     
        $surveyTypeSelect = $session->surveyTypeSelect;

The above function - session data is empty. 上面的功能-会话数据为空。

You are setting a new session namespace in that function rather than retrieving the one you already had. 您正在该函数中设置一个新的会话名称空间,而不是检索已经拥有的名称空间。 You could try creating your session, then setting it to registry using Zend_Registry::set('session', $session) then when you need it anywhere else you use $session = Zend_Registry::get('session'); 您可以尝试创建会话,然后使用Zend_Registry::set('session', $session)将其设置为注册表Zend_Registry::set('session', $session)然后在其他任何地方需要使用$session = Zend_Registry::get('session'); that way you ensure that you are using the same session namespace. 这样,您可以确保使用相同的会话名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM