开发者

Zend_session_savehandler_dbtable - strange problems

开发者 https://www.devze.com 2023-01-31 21:48 出处:网络
I have this config in application.ini: resources.session.save_path = APPLICATION_PATH \"/../data/session\"

I have this config in 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"

Database structure is 100% right and connection to db (working) is set above this. I'm getting error that session_id, save_path etc. are undefined indexes. After that I added this code to bootstrap:

    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();
    }

After that I'm getting errors that session handler didn't found bd adapter:

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

Zend documentation is in this case very poor and I simply don'开发者_开发知识库t know what could be wrong in my configuration.


i am not very sure where is your problem , but i wanted to share with you my $config array

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


Your config is close but not quite right. Here is the code I use in my application.ini file

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"

Just have to make sure the primary[] and primaryAssignment[] variables are set in the same order. That is all I needed to get my sessions saved to the database. No need to set anything in the bootstrap file :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号