简体   繁体   English

TYPO3扩展:从javascript访问TYPO3会话变量?

[英]TYPO3 extension: Accessing the TYPO3 session variable from javascript?

This may sound a little unprecise, but is it possible to change the TYPO3 session variable 这听起来可能有些不准确,但是可以更改TYPO3会话变量

$GLOBALS["TSFE"]->fe_user->setKey('ses', 't_minus', 0);

from javascript somehow for the variable to be processed within a listAction to specify certain records to be shown or not? 从JavaScript以某种方式在listAction内处理变量以指定要显示或不显示某些记录?

In more detail: I work on an extension for a calendar. 更详细地说:我正在研究日历的扩展名。 The calendar is generated in javascript (that's the part i'm not responsible for). 日历是用JavaScript生成的(这是我不负责的部分)。 The listAction basically generates a JSON object or records which have a unix timestamp within a specific interval (2 weeks in the past, 3 weeks in the future). listAction基本上会生成一个JSON对象或记录,该对象或记录在特定间隔(过去2周,将来3周)内具有unix时间戳。 The javascript has a button "one week forward"/"one week back". javascript有一个按钮“前进一周” /“前进一周”。 One week back should subtract 604800 (1 week) from the session variable, one week forward add 604800 (1 week) to the session variable. 向后一周应从会话变量中减去604800(1周),向前一周应向会话变量中添加604800(1周)。

In the listAction the session variable adjusts the timestamp interval (n weeks forward/backward) or rather which records should be put into the JSON object. 在listAction中,会话变量调整时间戳记间隔(向前/向后n周),或者将哪些记录放入JSON对象。

Is it possible to access the session variable from javascript or does this violate safety requirements? 是否可以从javascript访问会话变量,否则是否违反安全要求?

I would create a PHP function to change this session variable (eg with eID functionality) and call the function via AJAX in JavaScript. 我将创建一个PHP函数来更改此会话变量(例如,具有eID功能),然后通过JavaScript中的AJAX调用该函数。 More see here: https://seethroughweb.com/ajax-with-typo3/ 更多信息请参见: https//seethroughweb.com/ajax-with-typo3/

(Sorry, couldn't find a better manual in english, you need to use the new class names) (对不起,找不到英文更好的手册,您需要使用新的类名)

It is not possible to change TYPO3 session content directly via javascript. 无法直接通过javascript更改TYPO3会话内容。 It may be that you can access the PHP session cookie via javascript - I am not quite sure on that -, but the session variables are stored in the TYPO3 DB. 可能您可以通过javascript访问PHP会话cookie-我不太确定,但是会话变量存储在TYPO3 DB中。 They are serialized and encrypted via PHP and you won't be able to get access on these via Javascript. 它们通过PHP进行了序列化和加密,您将无法通过Javascript访问它们。 This is only possible via PHP. 这只能通过PHP实现。

What you could do: create oneWeekForwardAction and oneWeekBackAction in your controller. 您可以执行的操作:在控制器中创建oneWeekForwardActiononeWeekBackAction Read your session cookie and modifie it to your needs. 阅读您的会话cookie并根据您的需要进行修改。 These actions can be activated via Ajax. 这些动作可以通过Ajax激活。 For this to happen you have to create the appropriate links with the f:uri.action in advance in your Fluid template! 为此,您必须在Fluid模板中预先使用f:uri.action创建适当的链接! Place these strings somewhere in your JSON object. 将这些字符串放在JSON对象中的某个位置。 Then you can connect these links to the click events. 然后,您可以将这些链接连接到单击事件。

Don't forget to generate a special AJAX page type with page.config.disableAllHeaderCode . 不要忘记使用page.config.disableAllHeaderCode生成特殊的AJAX页面类型。 If you search for this and Ajax you will find examples, fe this one: 如果您搜索此内容并且使用Ajax ,则会找到示例,例如:

[ http://www.sklein-medien.de/tutorials/detail/erstellung-einer-typo3-extension-mit-ajax-aufruf/] [ http://www.sklein-medien.de/tutorials/detail/erstellung-einer-typo3-extension-mit-ajax-aufruf/]

It is from 2016 und uses Extbase/Fluid. 从2016年开始使用Extbase / Fluid。

It's not a question of safety. 这不是安全问题。 The idea of a session is, to bind to the same data on the server over a series of multiple HTTP requests. 会话的思想是通过一系列多个HTTP请求将其绑定到服务器上的相同数据。 Javascript lives in the Browser. Javascript位于浏览器中。 There is no direct access from JavaScript to the data on the server. JavaScript无法直接访问服务器上的数据。

If you are responsible for JS only, it's the job of the other person to provide an interface to the session data for you. 如果您仅负责JS,则另一个人的工作就是为您提供会话数据的接口。

And yes, I think it a good idea to synchronise your calculations in the Browser with the data in the server else calendar datas get quickly out of sync. 是的,我认为将浏览器中的计算结果与服务器中的数据同步是个好主意,否则日历数据很快就会不同步。 I would even go that far, that the server should be responsible for this kind of calculations, as it is more reliable than JS. 我什至会走得更远,因为服务器比JS更可靠,服务器应该负责这种计算。 So the guy responsible for PHP should do the main job and provide results to you ie via AJAX. 因此,负责PHP的人应该做主要工作并通过AJAX向您提供结果。

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

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