Search code examples
phpjoomlajoomla3.0

Joomla 3.9 - Home Page Disappeared When I published twice a custom Module Developed by me


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

Solution

  • 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.