dow57588 2019-01-24 11:24
浏览 38
已采纳

Joomla 3.9 - 主页消失当我发布两次由我开发的自定义模块时

I developed a joomla module, it was working fine. When it was published once but when i published it again on same page, then home page gone and i got 500 error, and if I tried to unpublished one module both got unpublished.

How to resolve that issue. As a guess i think i should create a dynamic id with every module. but i dont know how to do that in joomla.

This code is making problems.

function group_by_key($array) {
    $result = array();

    foreach ($array as $sub) {
        foreach ($sub as $k => $v) {
            $result[$k][] = $v;
        }
    }
    return $result;
}

$features_list = array(
    $features_list1 = group_by_key($features[0]),
    $features_list2 = group_by_key($features[1]),
    $features_list3 = group_by_key($features[2]),
    $features_list4 = group_by_key($features[3]),
);

Because i am getting below error.

Fatal error: Cannot redeclare group_by_key() (previously declared in E:\xampp\htdocs\joomla\do\modules\mod_xp_comparison\tmpl\default.php:31) in E:\xampp\htdocs\joomla\do\modules\mod_xp_comparison\tmpl\default.php on line 40
  • 写回答

2条回答 默认 最新

  • douguachi0056 2019-01-24 15:19
    关注

    You should try it this way:

    if (!function_exists('group_by_key')) {
        function group_by_key($array) {
            $result = array();
    
            foreach ($array as $sub) {
                foreach ($sub as $k => $v) {
                    $result[$k][] = $v;
                }
            }
            return $result;
        }
    }
    
    $features_list = array(
        $features_list1 = group_by_key($features[0]),
        $features_list2 = group_by_key($features[1]),
        $features_list3 = group_by_key($features[2]),
        $features_list4 = group_by_key($features[3]),
    );
    

    The reason of the above is that you cannot include (or declare) the same function twice. So if it is already defined in a Global scope in your default.php for example then it's just causing a conflict. Thus if you are not sure, then you have to use that function inside an if (!function_exists('any_function_name')) { ...// function ... } condition statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?