PHPCMS V9 全站推荐位文章链接为空
错误定位:
go函数存在bug
错误代码:
[php]
/**
* 获取内容地址
* @param $catid 栏目ID
* @param $id 文章ID
* @param $allurl 是否以绝对路径返回
*/
function go($catid,$id, $allurl = 0) {
static $category;
if(empty($category)) {
$siteids = getcache(‘category_content’,’commons’);
$siteid = $siteids[$catid];
$category = getcache(‘category_content_’.$siteid,’commons’);
}
$id = intval($id);
if(!$id || !isset($category[$catid])) return ”;
$modelid = $category[$catid][‘modelid’];
if(!$modelid) return ”;
$db = pc_base::load_model(‘content_model’);
$db->set_model($modelid);
$r = $db->get_one(array(‘id’=>$id), ‘`url`’);
if (!empty($allurl)) {
if (strpos($r[‘url’], ‘://’)===false) {
if (strpos($category[$catid][‘url’], ‘://’) === FALSE) {
$site = siteinfo($category[$catid][‘siteid’]);
$r[‘url’] = substr($site[‘domain’], 0, -1).$r[‘url’];
} else {
$r[‘url’] = $category[$catid][‘url’].$r[‘url’];
}
}
}
return $r[‘url’];
}
[/php]
修正方法:
//static $category;
注释掉$category变量以后,问题解决。
[php]
/**
* 获取内容地址
* @param $catid 栏目ID
* @param $id 文章ID
* @param $allurl 是否以绝对路径返回
*/
function go($catid,$id, $allurl = 0) {
//static $category;
if(empty($category)) {
$siteids = getcache(‘category_content’,’commons’);
$siteid = $siteids[$catid];
$category = getcache(‘category_content_’.$siteid,’commons’);
}
$id = intval($id);
if(!$id || !isset($category[$catid])) return ”;
$modelid = $category[$catid][‘modelid’];
if(!$modelid) return ”;
$db = pc_base::load_model(‘content_model’);
$db->set_model($modelid);
$r = $db->get_one(array(‘id’=>$id), ‘`url`’);
if (!empty($allurl)) {
if (strpos($r[‘url’], ‘://’)===false) {
if (strpos($category[$catid][‘url’], ‘://’) === FALSE) {
$site = siteinfo($category[$catid][‘siteid’]);
$r[‘url’] = substr($site[‘domain’], 0, -1).$r[‘url’];
} else {
$r[‘url’] = $category[$catid][‘url’].$r[‘url’];
}
}
}
return $r[‘url’];
}
[/php]