如果访客访问网站,Yii 2 重定向到登录 [英] Yii 2 redirecting to Login if Guest visit the website

查看:20
本文介绍了如果访客访问网站,Yii 2 重定向到登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人没有登录网站并且他只是访客,我需要一些建议如何重定向登录

I need some advice how to make redirecting to login if someone does not login into the website and he is only Guest

推荐答案

use Yii;
use yiihelpersUrl;

if ( Yii::$app->user->isGuest )
    return Yii::$app->getResponse()->redirect(array(Url::to(['site/login'],302)));

Use 可以在动作或视图中使用它,但如果你需要在很多动作中使用它,你可能需要查看 AccessControl 并在触发操作之前限制访问

Use can use it in actions or views , but if you need to use it in lots of actions you probably need look at AccessControl and restrict access even before action is fired

这篇关于如果访客访问网站,Yii 2 重定向到登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆