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 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计