我在使用的分類信息的時候需要添加聯動屬性,結果去添加聯動屬性的時候,發(fā)現只可以添加一級聯動和三級聯動。
二級聯動無法添加了。
在自己的5.6的后臺添加的時候,發(fā)現是可以的。估計又是5.7版本的bug了。
于是分析了代碼,和大家分享下解決的辦法:
首先我們找到我們的模板源碼下面的 dede/stepselect_main.php 這個文件,
將這段代碼
else if($action=='addenum_save')
{
if(empty($ename) || empty($egroup))
{
Showmsg("類別名稱或組名稱不能為空!","-1");
exit();
}
if($issign == 1 || $topvalue == 0)
{
$enames = explode(',', $ename);
foreach($enames as $ename)
{
$arr = $dsql->GetOne("SELECT * FROM `dede_sys_enum` WHERE egroup='$egroup' AND (evalue MOD 500)=0 ORDER BY disorder DESC ");
if(!is_array($arr)) $disorder = $evalue = ($issign==1 ? 1 : 500);
else $disorder = $evalue = $arr['disorder'] + ($issign==1 ? 1 : 500);
$dsql->ExecuteNoneQuery("INSERT INTO `dede_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`)
VALUES('$ename','$evalue','$egroup','$disorder','$issign'); ");
}
WriteEnumsCache($egroup);
ShowMsg("成功添加枚舉分類!".$dsql->GetError(), $ENV_GOBACK_URL);
exit();
} else if ($issign == 2 && $topvalue != 0)
{
$minid = $topvalue;
$maxnum = 500; // 三級子類最多500個
$enames = explode(',', $ename);
foreach ($enames as $ename)
{
$arr = $dsql->GetOne("SELECT * FROM `dede_sys_enum` WHERE egroup='$egroup' AND evalue LIKE '$topvalue.%%%' ORDER BY evalue DESC ");
if(!is_array($arr))
{
$disorder = $minid;
$evalue = $minid.'.001';
}
else
{
$disorder = $minid;
preg_match("#([0-9]{1,})\.([0-9]{1,})#", $arr['evalue'], $matchs);
$addvalue = $matchs[2] + 1;
$addvalue = sprintf("d", $addvalue);
$evalue = $matchs[1].'.'.$addvalue;
}
$sql = "INSERT INTO `dede_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`)
VALUES('$ename','$evalue','$egroup','$disorder','$issign'); ";
// echo $sql;exit;
$dsql->ExecuteNoneQuery($sql);
}
// echo $minid;
WriteEnumsCache($egroup);
ShowMsg("成功添加枚舉分類!", $ENV_GOBACK_URL);
exit();
} else {
$minid = $topvalue;
$maxid = $topvalue + 500;
$enames = explode(',', $ename);
foreach($enames as $ename)
{
$arr = $dsql->GetOne("SELECT * FROM `dede_sys_enum` WHERE egroup='$egroup' AND evalue>$minid AND evalue<$maxid ORDER BY evalue DESC ");
if(!is_array($arr))
{
$disorder = $evalue = $minid+1;
}
else
{
$disorder = $arr['disorder']+1;
$evalue = $arr['evalue']+1;
}
$dsql->ExecuteNoneQuery("INSERT INTO `dede_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`)
VALUES('$ename','$evalue','$egroup','$disorder','$issign'); ");
}
WriteEnumsCache($egroup);
ShowMsg("成功添加枚舉分類!", $ENV_GOBACK_URL);
exit();
}
}
替換為:
else if($action=='addenum_save')
{
if(empty($ename) || empty($egroup)) {
Showmsg("類別名稱或組名稱不能為空!","-1");
exit();
}
if($issign==1 || $topvalue==0)
{
$enames = explode(',', $ename);
foreach($enames as $ename)
{
$arr = $dsql->GetOne("Select * From `dede_sys_enum` where egroup='$egroup' And (evalue mod 500)=0 order by evalue desc ");
if(!is_array($arr)) $disorder = $evalue = ($issign==1 ? 1 : 500);
else $disorder = $evalue = $arr['disorder'] + ($issign==1 ? 1 : 500);
$dsql->ExecuteNoneQuery("Insert into `dede_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`)
values('$ename','$evalue','$egroup','$disorder','$issign'); ");
}
WriteEnumsCache($egroup);
ShowMsg("成功添加枚舉分類!".$dsql->GetError(), $ENV_GOBACK_URL);
exit();
}
else
{
$minid = $topvalue;
$maxid = $topvalue + 500;
$enames = explode(',', $ename);
foreach($enames as $ename)
{
$arr = $dsql->GetOne("Select * From `dede_sys_enum` where egroup='$egroup' And evalue>$minid And evalue<$maxid order by evalue desc ");
if(!is_array($arr))
{
$disorder = $evalue = $minid+1;
}
else
{
$disorder = $arr['disorder']+1;
$evalue = $arr['evalue']+1;
}
$dsql->ExecuteNoneQuery("Insert into `dede_sys_enum`(`ename`,`evalue`,`egroup`,`disorder`,`issign`)
values('$ename','$evalue','$egroup','$disorder','$issign'); ");
}
WriteEnumsCache($egroup);
ShowMsg("成功添加枚舉分類!", $ENV_GOBACK_URL);
exit();
}
}
然后保存,在系統(tǒng)后臺更新系統(tǒng)緩存就可以了的?,F在在后臺的聯動類別管理里面就可以增加二級選擇了。