Fatal Error:call to a member function fpage () on a non-object solution

Source: Internet
Author: User
Fatal Error:call to a member function fpage () on a non-object
Smarty inside me by calling the paging function, page.class.php has been called on the page, and has been instantiated, the specific statement is this:
/* Product List */
function get_product_list ($cat _id)
{
if ($cat _id)
{
$num = 6;
$where = "where classid= ' $cat _id ' and shenhe=1";
$sql 1 = $GLOBALS [' DB ']->query ("select * from". $GLOBALS [' DB ']->table (' product '). $where. ");
$total = $GLOBALS [' db ']->num_rows ($sql 1);
}
Else
{
$num = 6;
$where = "where shenhe=1";
$sql 2= $GLOBALS [' DB ']->query ("select * from". $GLOBALS [' DB ']->table (' product '). $where. ");
$total = $GLOBALS [' db ']->num_rows ($sql 2);
}
$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;
}
/* Initialize data */
$smarty->assign (' Ur_here ', $db->ur_here (' Product_class ', $cat _id));
$smarty->assign (' product_category ', $db->get_product_category (')); Product Show left Category list
$smarty->assign (' Product_list ', get_product_list ($cat _id)); Product List
$smarty->assign (' Page_nav ', $page->fpage (Array (3,4,5,6,7,0,1,2,8)));//Product paginationThis error, to see which great God to give doubts, greatly appreciated ~!
------Solution--------------------
The $page is initialized in the function. That is, he is a local variable, and of course you cannot use it outside of the function.
------Solution--------------------
Returned as a function's return value, for example:
return $product _list;
Change to return Array (
' List ' = $product _list,
' Fpage ' = $page->fpage (Array (3,4,5,6,7,0,1,2,8)),
)

------Solution--------------------
The function return value is changed to # # as written.

$smarty->assign (' Product_list ', get_product_list ($cat _id)); Product List
$smarty->assign (' Page_nav ', $page->fpage (Array (3,4,5,6,7,0,1,2,8)));
Switch
$ar = get_product_list ($cat _id);
$smarty->assign (' product_list ', $ar [' list ']); Product List
$smarty->assign (' Page_nav ', $ar [' fpage ']);
------Solution--------------------
function get_product_list ($cat _id)
{
Global $page;Add this sentence.
if ($cat _id)
..........

Other no changes required
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.