0

我在 application.ini 中有这个配置:

resources.session.save_path = APPLICATION_PATH "/../data/session"
resources.session.use_only_cookies = true
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "jm_sessions"
resources.session.saveHandler.options.primary.session_id = "session_id"
resources.session.saveHandler.options.primary.save_path = "save_path"
resources.session.saveHandler.options.primary.name = "name"
resources.session.saveHandler.options.primaryAssignment.sessionId = "sessionId"
resources.session.saveHandler.options.primaryAssignment.sessionSavePath = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment.sessionName = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"

数据库结构是 100% 正确的,并且与 db(工作)的连接设置在此之上。我收到 session_id、save_path 等是未定义索引的错误。之后,我将此代码添加到引导程序:

    protected function _initCoreSession()
    {

            $config = array(

                    'name' => 'jm_sessions', 
                    'primary' => array(

                            'session_id', 
                            'save_path', 
                            'name'
                    ), 
                    'primaryAssignment' => array(

                            'sessionId', 
                            'sessionSavePath', 
                            'sessionName'
                    ), 
                    'modifiedColumn' => 'modified', 
                    'dataColumn' => 'session_data', 
                    'lifetimeColumn' => 'lifetime'
            );

            Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
            Zend_Session::start();
    }

之后,我收到会话处理程序未找到 bd 适配器的错误:

Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for
Zend_Session_SaveHandler_DbTable'

Zend 文档在这种情况下非常糟糕,我根本不知道我的配置可能有什么问题。

4

2 回答 2

1

我不太确定您的问题出在哪里,但我想与您分享我的$config阵列

public function _initsession() {
        $config = array(
            'name' => 'session', //table name as per Zend_Db_Table
            'primary' => array(
                'session_id', //the sessionID given by PHP
                'save_path', //session.save_path
                'name', //session name
            ),
            'primaryAssignment' => array(
                //you must tell the save handler which columns you
                //are using as the primary key. ORDER IS IMPORTANT
                'sessionId', //first column of the primary key is of the sessionID
                'sessionSavePath', //second column of the primary key is the save path
                'sessionName', //third column of the primary key is the session name
            ),
            'modifiedColumn' => 'modified', //time the session should expire
            'dataColumn' => 'session_data', //serialized data
            'lifetimeColumn' => 'lifetime', //end of life for a specific record
        );
        $adapter = new Zend_Session_SaveHandler_DbTable($config);
        Zend_Session::setSaveHandler($adapter);
        Zend_Session::start();
        $session = new Zend_Session_Namespace('App');
        Zend_Registry::set("session", $session);
    }
于 2010-12-24T12:22:45.477 回答
1

您的配置很接近但不太正确。这是我在 application.ini 文件中使用的代码

resources.db.adapter = "Pdo_Mysql" 
resources.db.params.host = "localhost"
resources.db.params.username = "grabby_user" 
resources.db.params.password = "w8F4cqZpaNz2WeS6"
resources.db.params.dbname = "grabby"
resources.db.isDefaultTableAdapter = true

resources.session.name = "Grabby"
resources.session.save_path = APPLICATION_PATH "/../data/session"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 3600
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary[] = "session_id"
resources.session.saveHandler.options.primary[] = "save_path"
resources.session.saveHandler.options.primary[] = "name"
resources.session.saveHandler.options.primaryAssignment[] = "sessionId"
resources.session.saveHandler.options.primaryAssignment[] = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment[] = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"

只需确保 primary[] 和 primaryAssignment[] 变量以相同的顺序设置。这就是我将会话保存到数据库所需的全部内容。无需在引导文件中设置任何内容 :)

于 2011-05-05T23:47:11.530 回答