Issuing a redirect from a Joomla module(从 Joomla 模块发出重定向)
问题描述
我对 Joomla 不是很熟悉,但我的任务是编写一个模块,该模块的功能与问题无关.
I am not really familiar with Joomla but I have been tasked with writing a module which functionality is irrelevant to the question.
其中一个要求是,如果模块被加载,它应该检查用户是否登录,如果没有 - 将他重定向到特定的 URL.
One of the requirements is that if the module is loaded, it should check if the user is logged in and if not - redirect him into a specific URL.
经过一番搜索,我想出了类似的东西,但这显然不是一个有效的答案:
After some searching I came up with something like this, but it's obviously not a working answer:
$user =& JFactory::getUser();
if (!$user->id) {
include_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . "controller.php"; // assuming com_content
$contentController = new ContentController();
$link = JRoute::_("my url");
$contentController->setRedirect($link);
return;
}
我认为问题在于获取控制器.创建一个新的控制器当然不是要走的路.有没有办法从 Joomla 模块获取当前控制器并发出重定向?
I think the problem lies in getting to the controller. Creating a new controller certainly isn't the way to go. Is there a way to get the current controller from a Joomla module and the issue a redirect?
感谢您的回答.
推荐答案
我在我的每个控制器构造中调用这个静态函数
i call this static function in each of my controllers construct
static function forceLoggedIn(){
$user = JFactory::getUser();
if($user->guest||$user->id == 0)
{
$error = JText::_('YOU MUST BE LOGGED IN');
//base xkè altrimenti andrebbe in loop di redirect
JFactory::getApplication()->redirect(JURI::base(), $error, 'error' );
return false;
}
}
这篇关于从 Joomla 模块发出重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Joomla 模块发出重定向
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
