设置cookie后跳转页面 标准写法是什么 #3537
-
设置cookie后跳转页面 标准写法是什么 |
Beta Was this translation helpful? Give feedback.
Answered by
limingxinleo
May 2, 2021
Replies: 1 comment
-
很简单啊,跳转前设置 cookies 就行了 路由 <?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\HttpServer\Router\Router;
Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController::index');
Router::get('/cookies', App\Controller\IndexController::class . '::cookies'); 控制器 <?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller;
use Hyperf\HttpMessage\Cookie\Cookie;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
class IndexController
{
public function index(ResponseInterface $response)
{
return $response->withCookie(new Cookie('test', 'Hello World'))->redirect('/cookies');
}
public function cookies(RequestInterface $request)
{
return $request->getCookieParams();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
limingxinleo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
很简单啊,跳转前设置 cookies 就行了
路由
控制器