ホームページ  >  記事  >  バックエンド開発  >  致命的なエラー: 非オブジェクトのメンバー関数 fpage() の呼び出し

致命的なエラー: 非オブジェクトのメンバー関数 fpage() の呼び出し

WBOY
WBOYオリジナル
2016-06-23 13:57:561056ブラウズ

Smarty では、ページング関数を呼び出します。Pag​​e.class.php がページ上で呼び出され、インスタンス化されています。
/*product list*/
function get_product_list($cat_id)
{
if( $cat_id)
{
$num=6;
$where = " where classid='$cat_id' および 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." 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=new page($total,$num);

生成されたオブジェクトが有効なオブジェクトであるかどうかを確認します。 total と num の値もあります。


$page=new page($total,$num);

生成されたオブジェクトが有効なオブジェクトであるかどうかを確認します。 total と num の値もあります。

Page Object ( [total:private] => 5 [listRows:private] => 6 [limit:private] => Limit 0, 6 [uri:private] => /zangbaoshengwu/cpxx.php? [pageNum:private] => 1 [config:private] => Array ( [header] => レコード [prev] => 前のページ [次] => 次のページ [最初] => [last] => 最後のページ ) [listNum:private] => 8 [page] => 1 )
$total、$num はすべて有効です

$page は関数内で初期化されます。つまりローカル変数なので、当然関数外では使えません。

$page は関数内で初期化されます。つまりローカル変数なので、当然関数外では使えません。

では、具体的にはどのように書けばいいのでしょうか?関数内ではどうやって書けばいいのでしょうか?

関数の戻り値として返されます。例:

return $product_list;
return array( 'list'=>$product_list,

'fpage'=>$page->fpage(array) (3、4、5、6、7、0、1、2、8))、
)



関数の戻り値として返されます。例:
return $product_list;

return array(

'list'=>$product_list,

'fpage'=>$page->fpage( array(3 ,4,5,6,7,0,1,2,8)),
)


意味は分かるけど、どうやって実装すればいいのか分からない。
$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))); //商品のページネーション
はここにあります。

関数の戻り値を #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']);

関数の戻り値を #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']);

空の配列値リストを出力する方法:

Array ( [list] => fpage ] => 1 合計 5 つのレコードがあります。各ページに 5 つのレコードが表示されます。このページ 1/1 ページには 1 ~ 5 のレコードが表示されます。
完全なプログラムは次のとおりです:
/*product list*/
function get_product_list ($cat_id)
{
if($cat_id)
{
$num=6;
$where = " where classid=$cat_id および 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);
$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['製品 ID']);
$ product_list[] = array(
"id" => $row['productid'],
"title" => $row['title'],
"image" => $row['image']
);
}
//return $product_list;
return array(
'list' => $product_list,
'fpage' => $page->fpage(array(3) ,4,5,6, 7,0,1,2,8))
);
}

/*初期化データ*/
$smarty->assign('ur_here',$db->ur_here( 'product_class',$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)
.....

その他の変更は必要ありません

申し訳ありませんが、 SQL クエリ ステートメントの書き方が間違っていました:
$sql="select * from ".$GLOBALS['db']->table('product').$where."order by addtime desc {$page-> limit}";
while($row=$GLOBALS['db']->fetch_array($sql))
$GLOBALS['db']-query() がここにありません;


皆さん、申し訳ありません。量が少ないので、量は少し少ないですが、ご了承ください〜

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。