[英]TYPO3 set a cookie within a controller action
我嘗試在通過 typenumcall 調用的常規 controller 操作中設置 cookie。 我在 TYPO3 v 10.4
public function redirectCookieAction(): ResponseInterface
{
//do magic stuff...
/** @var \TYPO3\CMS\Core\Http\Response $response */
$response = GeneralUtility::makeInstance(ResponseFactory::class)->createResponse(200);
$response->withHeader('Set-Cookie', 'cookiename' . '=' . 'cookievalue' . '; Path=/; Max-Age=' . (time()+60*60*24*30));
return $response;
}
我嘗試使用 PSR7-HTTP-Response 但由於某種原因在調用操作后未設置 cookie。 似乎 $response object 被完全忽略了。 如何正確使用 ResponseInterface?
我已經看到了這個線程,但它不在中間件中,也沒有 fe_session: TYPO3 how to set custom cookie inside a form finisher
由於 $response 返回自身的新實例,因此您必須將其分配給變量,如下所示
/** @var \TYPO3\CMS\Core\Http\Response $response */
$response = GeneralUtility::makeInstance(ResponseFactory::class)->createResponse(200);
$response = $response->withAddedHeader('Set-Cookie', 'cookiename' . '=' . 'cookievalue' . '; Path=/; Max-Age=' . (time()+60*60*24*30));
return $response;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.