[英]Joomla login page, if user is already logged redirect to home page
I think I'm missing something in the Joomla login behaviour. 我认为我在Joomla登录行为中缺少某些内容。 I read a lot of post but can't find the answer of what I looking for. 我读了很多文章,但找不到我想要的答案。 Let's say you have login page (ie: yoursite.com/login), if you login, Joomla correctly brings you to the target page you choose. 假设您拥有登录页面(例如:yoursite.com/login),如果您登录,Joomla会将您正确地带到您选择的目标页面。 The problem is : if you then go back to the login page yoursite.com/login, the redirect doesn't work no more. 问题是:如果您随后返回登录页面yoursite.com/login,则重定向将不再起作用。 In fact if you refresh the page the login fields vanish and all it remains is the logout button. 实际上,如果刷新页面,则登录字段消失,剩下的只是注销按钮。
I tried 我试过了
$user = JFactory::getUser();
if($user->id == 1)
{
// redirect here
}
I tried in Joomla 2.5 and 3.x, the behaviour is the same. 我在Joomla 2.5和3.x中尝试过,其行为是相同的。 Am I missing something? 我想念什么吗?
Because it's not the same layout. 因为布局不一样。
If the user is guest, you are looking at the "default_login.php" layout, which - I gather - is the one you already modified. 如果用户是访客,那么您正在查看的是“ default_login.php”布局,我已经收集了该布局,您已经对其进行了修改。 But if the user is logged, you are looking at the "default_logout.php" layout, which you need to override as well. 但是,如果已登录用户,则您正在查看的是“ default_logout.php”布局,您还需要覆盖它。
Before you redirect to home page or any other page you must called getApplication like this. 在重定向到主页或任何其他页面之前,您必须像这样调用getApplication。
$mainframe = JFactory::getApplication();
$user = JFactory::getUser();
if($user->id == 1)
{
// redirect here
$mainframe->redirect('index.php');
}else{
// redirect to login page
$mainframe->redirect('login');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.