不同的Magento会话类型有什么区别 [英] What's the difference between the different Magento session types

查看:78
本文介绍了不同的Magento会话类型有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关Magento中可用的不同会话类型的差异的一些信息.

I looking for some information about the difference of the different session types available in Magento.

有一个核心会话,一个客户会话和一个结帐会话.但是我不太确定何时使用哪一种,以及它们的行为方式会有所不同.它们是否都同时有效,还是结账会话早于核心会话而变得无效?

There's a core session, a customer session and a checkout session. But I'm not quite sure when to use which one and how they might behave differently. Are they all valid for the same time or does a checkout session get invalidated earlier than the core session?

推荐答案

好问题!

直接回答问题:所有会话模型的生存期都相同.会话生存期由Magento和服务器软件中的配置确定. 您可能想问的(用Magento处理各种会话的方式)是:给定会话类型的数据可以保留多长时间?"

To answer the question directly: All session models lifetime are the same. Session lifetime is determined by configuration in Magento and in your server software. What you are probably intending to ask (in the Magento way of handling various sessions) is, "How long is the data for a given session type persisted?"

答案是实现之一,所以最好的方法是在代码中搜索实例化点.要使用的搜索模式是 getSingleton('core/session')(或任何会话模型).任何被调用的地方(如果是第一次)都会在$_SESSION超全局变量中创建会话名称空间(如下所述).

The answer is one of implementation, so the best way is to search the code for instantiation points. The search pattern to use is getSingleton('core/session') (or whichever session model). Anywhere that this is called - if it's the first time it's encountered - will create the session namespace (explained below) in the $_SESSION superglobal.

因此,会话永远不会被杀死",但是数据会根据实现方式清除.众所周知,执行此操作的是checkout/session,因为下订单后会擦除数据.

So, sessions are never "killed", but the data gets cleared depending on the implementation. The one that does this notoriously is checkout/session, as the data gets wiped after an order is placed.

除此之外,您还可以依靠该会话满足您的持久性需求.

Beyond this, you can rely that session is there for your persistence needs.

会话模型使用抽象基类来定义各种API,Mage_Core_Model_Session_Abstract.此类填补了以下角色/功能:

Session models in Magento use an abstract base class to define an API of sorts, Mage_Core_Model_Session_Abstract. This class fills the following roles/functions:

  1. 通过init()方法进行会话命名间隔,从字面上将$_SESSION[$namespace]下每种类型的存储值分开
  2. 用于(连接到)与会话相关的配置设置(包括cookie生存期,SID,安全设置等)的说明
  3. Flash消息的存储和检索(addError()addMessage()addNotice()addSuccess())
  4. 会话存储配置和方法的信
  5. 用于通过Varien_Object::__call()随意设置参数的重载(魔术获取器和设置器). *请注意,会话具有经过修改的魔术吸气剂,可让您从会话中检索数据并通过一次调用将其取消设置(例如$session->getSomeParam(true))
  1. Session namespacing via the init() method, literally separating stored values for each type under $_SESSION[$namespace]
  2. Getters for (connection to) the session-related configuration settings (including cookie lifetime, SID, security settings, etc.)
  3. Flash message storage and retrieval (addError(), addMessage(), addNotice(), and addSuccess())
  4. Getter for session storage configuration and methods
  5. Overloading (magic getters and setters) for setting params at will through Varien_Object::__call(). *Note that sessions have a modified magic getter which allows you to retrieve a datum from session and unset it with one call (e.g. $session->getSomeParam(true))

因此,如果希望模块具有自己的会话名称空间,只需将会话模型声明为从会话摘要扩展并在受保护的_construct()调用$this->init('namespace')中进行.

So, if you want your module to have its own session namespace, simply declare a session model as extending from the session abstract and in the protected _construct() call $this->init('namespace').

会话模型的所有数据将在会话名称空间下的数组键中设置;对于核心,应该是:

All data for session models will be set in array keys under the session namespace; for core this would be:

$session = Mage::getSingleton('core/session')->setSomeValue('Some string');

可以表示为

$_SESSION['core']['some_value'] = 'Some string'

这篇关于不同的Magento会话类型有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆