错字3 9.5.8.
我们正在实现一个包含多个步骤的新闻通讯订阅流程,在提交第二步时,我们在完成器中查询 graphQL,以查看电子邮件是否有效订阅 - 并且我们使用电子邮件地址的“状态”设置 cookie。
setcookie("isEmailSubscribable", ($content->data->isEmailSubscribable) ? "1" : "0", time() - 3600, "/", "x.at", false);
我们必须根据写入 cookie 的“状态”在第三步显示一条消息。但无论我怎么尝试,cookie 都没有被设置(我猜)。
cookies 和typo3 是怎么回事?现在在表单整理器中设置 cookie 是否太晚了?但如果是的话我该如何解决这个问题?
非常感谢您的帮助。
整理器内部:
// Set a cookie
$this->getTypoScriptFrontendController()->fe_user->setKey('ses', 'value', 'test');
// Get the cookie
$this->getTypoScriptFrontendController()->fe_user->getKey('ses', 'test');
Value 可以是一个数组,它将序列化存储在数据库中fe_sessions.ses_data
更新:
或者您可以尝试使用 PSR-15 中间件:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/RequestHandling/Index.html
在您的中间件类中,您获得 $request 和 $response 并使用它们来设置或读取 cookie:
// Write a cookie
$response = $response->withAddedHeader(
'Set-Cookie',
$cookieName . '=' . $yourValue . '; Path=/; Max-Age=' . (time()+60*60*24*30)
);
// Read a cookie
$request->getCookieParams()[$cookieName];
您只需检查电子邮件地址请求,也许还有一个隐藏字段来检测您的请求是否已提交。