php ci 重定向,php – Slim 3中间件重定向

我想检查用户是否已登录.因此我有一个类巫婆返回true或false.现在我想要一个中间件来检查用户是否已登录.

$app->get('/login','\Controller\AccountController:loginGet')->add(Auth::class)->setName('login');

$app->post('/login','\Controller\AccountController:loginPost')->add(Auth::class);

Auth Class

class Auth {

protected $ci;

private $account;

//Constructor

public function __construct(ContainerInterface $ci) {

$this->ci = $ci;

$this->account = new \Account($this->ci);

}

public function __invoke($request,\Slim\Http\Response $response,$next) {

if($this->account->login_check()) {

$response = $next($request,$response);

return $response;

} else {

//Redirect to Homepage

}

}

}

因此,当用户登录时,页面将正确呈现.但是当用户未自动生成时,我想重定向到主页.但是如何?!

$response->withRedirect($router->pathFor('home');

这不起作用!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值