【问题标题】:How to track jos-Error in Joomla 2.5?如何在 Joomla 2.5 中跟踪 jos-Error?
【发布时间】:2014-09-13 21:21:29
【问题描述】:

我只为客人(未登录的用户)制作了我的菜单项之一。如果用户登录,它会从菜单中消失。它工作正常...

但我注意到,当我将访客菜单项的链接放入浏览器时,当我没有进入时,它显示非常恶心 jos-Error: You are not authorized to view this resource.

我想找到一种方法来跟踪此类错误并重定向到自定义 404 页面或其他页面。

请帮我解决这个问题。

谢谢

【问题讨论】:

    标签: php error-handling joomla2.5


    【解决方案1】:

    字符串您无权查看此资源位于JERROR_ALERTNOAUTHOR语言字符串并在includes/application.php函数中触发:

    public function authorise($itemid)
        {
            $menus  = $this->getMenu();
            $user   = JFactory::getUser();
    
            if (!$menus->authorise($itemid))
            {
                if ($user->get('id') == 0)
                {
                    // Redirect to login
                    $uri        = JFactory::getURI();
                    $return     = (string)$uri;
    
                    $this->setUserState('users.login.form.data', array( 'return' => $return ) );
    
                    $url    = 'index.php?option=com_users&view=login';
                    $url    = JRoute::_($url, false);
    
                    $this->redirect($url, JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'));
                }
                else {
                    JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
                }
            }
        }
    

    您可以更改此功能并添加重定向或使用您想要的消息更改文本字符串。

    可以使用redirect() 方法进行重定向。

    重定向语法示例:

    $app = JFactory::getApplication();
    $app->redirect(JRoute::_(JURI::root().'index.php'));
    

    请确保您不会在未创建 override system plugin 的情况下更改 application.php

    希望对你有帮助

    【讨论】:

    • 作为一个魅力!谢谢
    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2012-06-21
    • 2017-08-13
    • 2012-10-24
    • 2023-04-11
    • 2012-04-07
    相关资源
    最近更新 更多