欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Fatal error: Call to a member function fpage() on a non-object解决方案

程序员文章站 2024-01-05 22:33:22
...
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)
..........

其他无需改动
Fatal error: Call to a member function fpage() on a non-object解决方案

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


上一篇:

下一篇: