如何获取Joomla登录表单网址以进行重定向 [英] How to get Joomla login form url for redirection

查看:141
本文介绍了如何获取Joomla登录表单网址以进行重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义组件.现在,每个人都可以使用此组件访问页面.如果用户未登录,我想将其重定向到登录页面.如何获取登录页面网址?

I have custom component. For now everyone can access the page with this component. I want to redirect user to login page if he is not loged in. How to get login page url?

在组件视图中,我写:

if($user->id != 0) {
    ..
}
else {
    $link = JRoute::_(???????);
    $this->setRedirect($link);  
}

另一个问题-可以看到还是应该放在其他地方? 我正在使用Joomla 2.5.

Another question - is it ok to put into view or should I put it somwhere else? I am using Joomla 2.5.

推荐答案

尝试一下,

在该组件视图中,您只需要限制登录用户,

In that component view you have to restrict only for logged in users then,

$user = JFactory::getUser();
if($user->id != 0){

 // show your view
}
else{

$mainframe = JFactory::getApplication();
$mainframe->redirect('index.php?option=com_users&view=login');
}

您可以在view.html.php,布局等内部的任何位置使用此代码.

You can use this code any where inside view.html.php,layouts etc.

这篇关于如何获取Joomla登录表单网址以进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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