我在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(working)的连接。我收到的错误是session_id,save_path等是未定义的索引。之后我将此代码添加到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();
}
之后我收到会话处理程序没有找到bd adapter的错误:
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for
Zend_Session_SaveHandler_DbTable'
Zend文档在这种情况下非常糟糕,我根本不知道我的配置可能出现什么问题。
答案 0 :(得分: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);
}
答案 1 :(得分: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 []变量以相同的顺序设置。 这就是我将会话保存到数据库所需的全部内容。无需在引导程序文件中设置任何内容:)