[英]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. 我开发了一个joomla模块,它运行正常。 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.
当它发布一次,但是当我在同一页面上再次发布它时,主页消失了,并且出现500错误,如果我尝试取消发布一个模块,那么两个模块都将取消发布。
How to resolve that issue. 如何解决该问题。 As a guess i think i should create a dynamic id with every module.
猜想我应该为每个模块创建一个动态ID。 but i dont know how to do that in joomla.
但是我不知道如何在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
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. 因此,例如,如果已经在您的
default.php
中的Global范围中定义了它,那么它只会引起冲突。 Thus if you are not sure, then you have to use that function inside an if (!function_exists('any_function_name')) { ...// function ... }
condition statement. 因此,如果不确定,则必须在
if (!function_exists('any_function_name')) { ...// function ... }
条件语句中使用该函数。
If you want to follow standard Joomla practices, instead of placing custom functions in the layout, create a helper class ( helper.php
): 如果要遵循标准的Joomla惯例,而不是在布局中放置自定义函数,请创建一个帮助器类(
helper.php
):
defined('_JEXEC') or die;
class ModXpComparisonHelper
{
public static function group_by_key($array)
{
$result = array();
foreach ($array as $sub)
{
foreach ($sub as $k => $v)
{
$result[$k][] = $v;
}
}
return $result;
}
}
Include the helper in main module file ( mod_xp_comparison.php
): 将帮助程序包括在主模块文件(
mod_xp_comparison.php
)中:
JLoader::register('ModXpComparisonHelper', __DIR__ . '/helper.php');
And then call the function when needed: 然后在需要时调用该函数:
$features_list = array(
$features_list1 = ModXpComparisonHelper::group_by_key($features[0]),
$features_list2 = ModXpComparisonHelper::group_by_key($features[1]),
$features_list3 = ModXpComparisonHelper::group_by_key($features[2]),
$features_list4 = ModXpComparisonHelper::group_by_key($features[3]),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.