Fatal error: Call to a member function fpage() on a non-object
smarty里面我通过调用分页函数,page.class.php已经在页面调用过,并且已经实例化,具体语句是这样的:
/*产品列表*/
function get_product_list($cat_id)
{
if($cat_id)
{
$num=6;
$where = " where classid='$cat_id' and shenhe=1 ";
$sql1 = $GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('product').$where."");
$total = $GLOBALS['db']->num_rows($sql1);
}
else
{
$num=6;
$where = " where shenhe=1 ";
$sql2=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('product').$where."");
$total=$GLOBALS['db']->num_rows($sql2);
}
$page=new page($total,$num);
//echo $total;
//exit();
$sql="select * from ".$GLOBALS['db']->table('product').$where."order by addtime desc {$page->limit}";
while($row=$GLOBALS['db']->fetch_array($sql))
{
$url=$GLOBALS['db']->rewrite_url('cpxx_xx',$row['productid']);
$product_list[]=array(
"id" => $row['productid'],
"title" => $row['title'],
"image" => $row['image']
);
}
return $product_list;
}
/*初始化数据*/
$smarty->assign('ur_here',$db->ur_here('product_class',$cat_id));
$smarty->assign('product_category',$db->get_product_category('')); //产品展示左侧分类列表
$smarty->assign('product_list',get_product_list($cat_id)); //产品列表
$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8))); //产品分页这句出错,看看哪位大神给解惑,不胜感激~!
------解决方案--------------------$page 是在函数中初始化的。也就是他是一个局部变量,当然你不能在函数外使用。
------解决方案--------------------作为函数的返回值返回,例如:
return $product_list;
改为 return array(
'list'=>$product_list,
'fpage'=>$page->fpage(array(3,4,5,6,7,0,1,2,8)),
)
。
------解决方案--------------------函数返回值改成#5那样写。
$smarty->assign('product_list',get_product_list($cat_id)); //产品列表
$smarty->assign('page_nav',$page->fpage(array(3,4,5,6,7,0,1,2,8)));
改为:
$ar = get_product_list($cat_id);
$smarty->assign('product_list',$ar['list']); //产品列表
$smarty->assign('page_nav',$ar['fpage']);
------解决方案--------------------function get_product_list($cat_id)
{
global $page; //加上这句
if($cat_id)
..........
其他无需改动