[英]Strange Zend_Session behaviour using Zend_Application
I'm writing to see if someone of you guys has encountered this problem before and have a chance to understand why it happened to me. 我正在写信,看看你们中是否有人以前曾遇到过此问题,并且有机会了解我为什么会发生此问题。
This is the story. 这就是故事。
I developed many ZF applications before Zend Framework v. 1.8, then I've stopped for about 18 months. 我在Zend Framework v。1.8之前开发了许多ZF应用程序,但是我停了大约18个月。 Now I had to start a new project on which I decided to use Zend Framework again.
现在,我不得不开始一个新项目,决定再次使用Zend Framework。
On my local server I had the version 1.11.3 installed, so I didn't download the latest release. 在本地服务器上,我安装了1.11.3版本,因此没有下载最新版本。
Before the use of Zend_Application with the Bootstrap.php file I used to start sessions putting my session options in my config.ini file and then loading them into a Zend_Session instance like this: 在将Zend_Application与Bootstrap.php文件一起使用之前,我曾经开始过会话,将会话选项放在config.ini文件中,然后将其加载到Zend_Session实例中,如下所示:
config.ini config.ini
sessions.name = NAME
sessions.use_only_cookies = 1
sessions.save_path = APPLICATION_PATH "/../tmp/sessions"
sessions.strict = on
sessions.remember_me_seconds = 1800
index.php (into the public webserver directory) before starting the application: 在启动应用程序之前将index.php(进入公共Web服务器目录):
Globals::startSession();
custom Globals class with various useful methods: 具有各种有用方法的自定义Globals类:
class Globals
{
static public function startSession()
{
$sessions_conf = self::getConfig()->sessions;
Zend_Session::setOptions($sessions_conf->toArray(););
Zend_Session::start();
}
}
This has always worked very well, enabling my sessions (used with Zend_Session_Namespace) and storing the session files in the save_path. 这一直很好,可以启用我的会话(与Zend_Session_Namespace一起使用)并将会话文件存储在save_path中。
With Zend_Application the manual tells to simply store the session options in the application.ini file under the "section" resources and Zend_Session will be configured automatically... 使用Zend_Application,该手册告诉您将会话选项简单地存储在application.ini文件中“部分”资源下,并且Zend_Session将自动配置。
I did it like this: 我这样做是这样的:
; SESSIONS
resources.session.name = NAME
resources.session.use_only_cookies = 1
resources.session.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.strict = on
resources.session.remember_me_seconds = 1800
It didn't worked. 它没有用。 So I tried to use (not at the same time!) the _initSession() and _initForceSession() methods in the Bootstrap.php file, putting them at the beginning of the class and writing into them the code:
因此,我尝试(而不是同时使用!)Bootstrap.php文件中的_initSession()和_initForceSession()方法,将它们放在类的开头并向其中写入代码:
$this->bootstrap('session');
But session were never working, data were not stored between http requests and session files were never written into the save_path... 但是会话永远无法正常工作,数据没有存储在http请求之间,会话文件也从未写入save_path ...
Could anyone, please, let me know if this is a normal behaviour (maybe I have missed something somewhere...)? 有人能告诉我这是否是正常行为吗(也许我在某处错过了某物...)?
Obviously I solved the problem re-implementing my older method (and it works perfectly), but I would like to learn how to use it correctly. 显然我解决了重新实现我的旧方法的问题(并且效果很好),但是我想学习如何正确使用它。
Thanks in advance. 提前致谢。
This should be a case of turn it on and it works, might have made it to easy. 这应该是打开它并起作用的情况,可能使它变得容易。
I think you may have a problem with how you set your options in your application.ini: 我认为您可能对如何在application.ini中设置选项有疑问:
; SESSIONS
resources.session.name = NAME
resources.session.name.use_only_cookies = 1
resources.session.name.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.name.strict = on
resources.session.name.remember_me_seconds = 1800
according to the reference manual 根据参考手册
To set a session configuration option, include the basename (the part of the name after "session.") as a key of an array passed to Zend_Session::setOptions().
要设置会话配置选项,请包括基本名称(名称在“ session。”之后的部分)作为传递给Zend_Session :: setOptions()的数组的键。
with your options set correctly the bootstrap _initSession() should just work. 正确设置选项后,引导程序_initSession()应该可以正常工作。
public function _initSession()
{
Zend_Session::start();
}
PS I use Zend_Session_Namespace all the time but rarely deal with a global session. PS我一直使用Zend_Session_Namespace,但很少处理全局会话。
In your Bootstrap.php add 在您的Bootstrap.php中添加
public function _initSession()
{
Zend_Session::start();
}
session options can be set in application.ini 会话选项可以在application.ini中设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.