简体   繁体   English

Joomla在会话上存储数据

[英]Joomla store data on session

I'm modifying a joomla component (jQuarks) in order to achieve the wanted behaviour from the module in order to do online quiz/exams. 我正在修改joomla组件(jQuarks),以便从模块中获得所需的行为,以便进行在线测验/考试。 Basically, I want to be able to use the session variable to store the following items: 基本上,我希望能够使用会话变量来存储以下项目:

  • UserId 用户身份
  • QuizSessionID (not the Joomla Session per se, since this is a jQarks "session") QuizSessionID(本身不是Joomla会话,因为这是jQarks的“会话”)
  • The quiz start time 测验开始时间
  • Last question answered page (or id, doesn't really matter, but since I'm using pages it's the best option) 上一个问题已回答的页面(或id并不重要,但是由于我正在使用页面,因此是最佳选择)
  • All the previously answered questions (ie, the question ID and the Answer ID) 先前所有已回答的问题(即问题ID和答案ID)

In order to achieve this I'm using JFactory::getSession() but I'm having some doubts. 为了实现这一点,我使用了JFactory :: getSession(),但是我有一些疑问。

The first one is: Is the session variable the best way to store this data? 第一个是:会话变量是存储此数据的最佳方法吗? If not, how or where can I store this info? 如果没有,我如何或在哪里存储此信息? Whenever the user clicks to navigate to the next page, I want to store the answer given and add it to the previously given answers. 每当用户单击导航到下一页时,我都想存储给出的答案并将其添加到先前给出的答案中。 Won't this make me have to constantly destroy and recreate the session? 这是否会让我不得不不断销毁并重新创建会话? If, by any chance a user needs to refresh the page, the current component behavior is to create a new quizSession thus reseting everything and storing nothing. 如果用户有任何机会需要刷新页面,则当前组件的行为是创建一个新的quizSession,从而重置所有内容而不存储任何内容。 Will the Joomla Session variable be enough to force the behavior I intend? Joomla Session变量是否足以强制执行我想要的行为? (resuming the quizSession that te user started) (恢复用户启动的quizSession)

If this is the wrong approach what should I use? 如果这是错误的方法,我应该怎么用? I'm not really versed developing for Joomla and haven't touched PHP in at least 3 years... 我并不精通Joomla的开发,并且至少三年没有接触过PHP ...

Best Regards 最好的祝福

I advice you not to use JSession, but try User state. 我建议您不要使用JSession,但请尝试使用用户状态。 It is widely used in Joomla for storing pagiantion, filters vars across pages. 它在Joomla中广泛用于存储分页,跨页面过滤var。 You can find info about it here . 您可以在此处找到有关它的信息

The only concern I have is a page refresh. 我唯一关心的是页面刷新。 The state will not be reset on refresh and I doubt that it is possible to do with Joomla API... 刷新时不会重置状态,我怀疑是否可以使用Joomla API ...

And one more thing - you do not need to store UserId in the session, because you can anytime retrieve it using this simple piece of code: 还有一件事-您不需要在会话中存储UserId,因为您可以随时使用以下简单代码来检索它:

$userId = JFactory::getUser()->id;

More info here . 更多信息在这里

SESSION is using for temporary data. SESSION用于临时数据。 You can use it to store data if you are not afraid to lose it. 如果您不怕丢失数据,则可以使用它来存储数据。

If you what to associate some data permanent use #__user_profiles table , like key value storage. 如果您要永久关联某些数据,请使用#__user_profiles table ,例如键值存储。

If you want have some analytic of it you must use your you DB structure. 如果要对其进行一些分析,则必须使用数据库结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM