プロが教えるわが家の防犯対策術!

このようなsmartyのphpの場合はどのようにページングをしたらいいのかわかりません。どなたかお知恵をお貸し下さい。

$cache_id = 'rakuten:' . serialize($_GET);
if (!$smarty->is_cached($tmpl_name, $cache_id)) {

$query = "楽天の情報を取得";
if ($affiliate_id) {
$query .= "&affiliateId=${affiliate_id}";
}
$query .= "&keyword=" . urlencode($_GET['keyword']);
$max = intval($_GET['max']);
if ($max > 0 && $max <= 30) {
$query .= "&hits=${max}";
}
if (isset($_GET['sort'])) {
$query .= "&sort=" . urlencode($_GET['sort']);
}
if (intval($_GET['genreId'])) {
$query .= "&genreId=" . intval($_GET['genreId']);
}
if ($_GET['field'] == 'use') {
$query .= "&field=0";
}
if (intval($_GET['imageFlag']) == 1) {
$query .= "&imageFlag=1";
}
if (intval($_GET['minPrice']) > 0) {
$query .= "&minPrice=" . intval($_GET['minPrice']);
}
if (intval($_GET['maxPrice']) > 0) {
$query .= "&maxPrice=" . intval($_GET['maxPrice']);
}
if ($_GET['orFlag'] == 'use') {
$query .= "&orFlag=1";
}
$client =& new HTTP_Client();
$client->get($query);
$resp =& $client->currentResponse();
if ($resp['code'] != 200) {
$smarty->assign('tid', intval($_GET["tid"]));
$smarty->assign('is_error', 1);
$smarty->assign('is_connection_error', 1);
$smarty->assign('errmsg', '接続に失敗しました。');
$smarty->caching = 0;
$smarty->display('error.tpl');
exit();
}

//print_r($resp['body']);
//exit();

$xml = new XML_Unserializer();
$xml->setOption('complexType', 'array');
$xml->setOption('forceEnum', array('Item'));
$result = $xml->unserialize($resp['body'], FALSE);
$data = $xml->getUnserializedData();

$status = $data['header:Header']['Status'];

if ($status == 'ClientError' ||
$status == 'ServerError' ||
$status == 'Maintenance') {
$smarty->assign('tid', intval($_GET["tid"]));
$smarty->assign('is_error', 1);
$smarty->assign('is_api_error', 1);
$smarty->assign('api_errmsg', $data['header:Header']['StatusMsg']);
$smarty->caching = 0;
$smarty->display('error.tpl');
exit();
}

// print("query = $query<br />\n");
// print_r($data);
// exit();

$smarty->assign('total_count', $data['Body']['itemSearch:ItemSearch']['count']);
$smarty->assign('items', $data['Body']['itemSearch:ItemSearch']['Items']['Item']);
}

// テンプレートの表示

$smarty->display($tmpl_name, $cache_id);

A 回答 (4件)

PEARのPAGERにて実装することが可能ですが、そちらの方法では考えておりますか?fuctoryにて生成されたデータをassignするだけでOKです。

ほかにもやり方があるので、載せておきますね。

参考URL:http://www.kazumanishihata.com/technology/smarty …

この回答への補足

お返事ありがとうございます。ご参考URLは以前私も見たことがあったのですが、お恥ずかしいことで私はPHP等初心者でどこにどのような形で使えばいいのか理解できません。お手数でなければどのように書き加えたらいいのか教えてほしいのですが・・・宜しくお願い致します。

補足日時:2008/07/24 07:53
    • good
    • 0
この回答へのお礼

お返事ありがとうございます。ご参考URLは以前私も見たことがあったのですが、お恥ずかしいことで私はPHP等初心者でどこにどのような形で使えばいいのか理解できません。お手数でなければどのように書き加えたらいいのか教えてほしいのですが・・・宜しくお願い致します。

お礼日時:2008/07/24 16:20

こんばんは。

エラーの内容は何でしょうか?出るエラーを毎回載せていただけるととても助かります。pager.phpがあるファイルパスはあっていますでしょうか?requireで絶対パスを指定して実行しても出ますでしょうか?

この回答への補足

こんにちは。いつもお返事していただきましてありがとうございます。

補足日時:2008/07/31 10:41
    • good
    • 0
この回答へのお礼

いつもありがとうございます。エラーコードは下記のとおりです。
Warning: main(pager/pager.php) [function.main]: failed to open stream: No such file or directory in /home/zoso-zepjimmy/public_html/server/app/rakuten/rakuten.php on line 10

Fatal error: main() [function.require]: Failed opening required 'pager/pager.php' (include_path='../../pear:../../smarty:.:/usr/local/lib/php') in /home/zoso-zepjimmy/public_html/server/app/rakuten/rakuten.php on line 10

ファイルパスがあっていないみたいです・・・PHP側に入れてみたみたのはこんな感じのものですが大丈夫でしょうか?

$params=array(
'perPage'=>2,
'itemData'=>itemData
);
$page = Pager::factory($params);
$pdata = $page->getPageData();
$plink = $page->getLinks();

$smarty->assign('pagelink',$plink);
$smarty->assign('pagedata',$pdata);

お礼日時:2008/07/30 19:20

なるほど。

検索結果の表示をしているわけですね。プログラムの追記はphp側とtpl側になります。
まず、Pager-2.4.5をダウンロードし、実行できるように
require_once('pager.php');
で読み込みます。

一連の流れは

/* phpfile側 */

require_once('pager.php');
#pagerのパラメータ
$params=array(
'perPage'=>1ページに検索結果を表示させたい数(例)2件ずつであれば2、10件ずつであれば10など...,
'itemData'=>こちらは検索結果(配列のデータ)を指定します。
);
#上記で作ったパラメータを使いペイジャーパーツを生成
$page = Pager::factory($params);
#ページのデータ
$pdata = $page->getPageData();
#ページのリンク
$plink = $page->getLinks();

これだけでペイジャーパーツが生成されます。あとは同じPHPのファイル内でTPLに対してアサインするだけです。
$smarty->assign('pagelink',$plink);
$smarty->assign('pagedata',$pdata);

/* tplfile側 */

{$pagelink}
{$pagedata}

お分かりになりますでしょうか?少し気になったのですが、検索結果をアサインする場合、php側でforeachか何かで回しながらアサインしているんでしょうか?

この回答への補足

こんばんは。いろいろご迷惑をかけたみたいで申し訳ありません。勝手ですがお返事お待ちしております。

補足日時:2008/08/07 21:44
    • good
    • 0
この回答へのお礼

いつもお返事ありがとうございます。非常に感謝しています。
「検索結果をアサインする場合、php側でforeachか何かで回しながらアサインしているんでしょうか?」
本当に申し訳ないのですが、質問の意味がわかりません・・・すみません。
転記されたものを使ってみましたがうまくいきませんでした・・・。はじめに転記したPHPの初めの部分は下記になります。
require_once('pager.php');を入れたのですが、この部分にエラーがでるみたいです・・・
できない生徒でもうしわけありません。


<?php
include('../incl_path.php');
include('../common/check_tmpl.php');
include('../common/sanitize_url.php');
include('../common/date_is_new.php');
set_include_path("${incl_path}pear" . PATH_SEPARATOR . "${incl_path}smarty" . PATH_SEPARATOR . get_include_path());
require_once('Smarty.class.php');
require_once('HTTP/Client.php');
require_once('XML/Unserializer.php');
require_once('pager.php');//転記した部分ですがエラーがでるみたいです。

// smartyの初期化
$smarty = new Smarty();
$smarty->template_dir = "../../templates/rakuten";
$smarty->config_dir = "../../config/rakuten";
$smarty->plugins_dir = array("./plugins", "../common/plugins");
$smarty->compile_dir = "../../templates_c/rakuten";
$smarty->cache_dir = "../../cache/rakuten";
$smarty->caching = 2;
$smarty->cache_lifetime = 43200;

$tmpl_name = check_template($smarty);
$smarty->config_load("tmpl.cfg", "id");
$developer_id = $smarty->get_config_vars('developer_id');
$affiliate_id = $smarty->get_config_vars('affiliate_id');
$smarty->assign('developer_id', $developer_id);
$smarty->assign('affiliate_id', $affiliate_id);

お礼日時:2008/07/29 07:41

遅くなりましてすいません。

その後ペイジャーは解決しましたでしょうか?最終的に表示したいデータ(配列)はどれにあたりますでしょうか?

この回答への補足

tpl側

{show_bom}
{if $total_count}
{items}
<p style="text-align : center; overflow : hidden;">
{if $is_image}<a href="{$affiliate_link}" target="_blank"><img src="{$medium_image_url}" alt="{$title|mb_truncate:100:" ..."}" style="border : 1px solid #999999;" /></a><br />{/if}
<a href="{$affiliate_link}" target="_blank">{$title|mb_truncate:100:" ..."}</a><br />
{$price|number_format}円<br />
(<a href="{$shop_affiliate_link}" target="_blank">{$shop_name|mb_truncate:100:" ..."}</a>)
</p>
{/items}
{else}{* if $total_count > 0 の条件を満たさない場合 *}
<p>検索条件に合う商品はありません。</p>
{/if}{* if $total_count > 0 *}

補足日時:2008/07/27 12:53
    • good
    • 0
この回答へのお礼

お返事ありがとうございます。恥ずかしいですが、まだ解決していません。いろいろ本などを購入し勉強しているのですが、なかなか理解できません。ペイジャーなんですが、Pager-2.4.5をダウンロードしてサーバーに落として利用すればいいのでしょうか。その辺もよくわかりません。このパーツはサーバー側でプログラムを動作させ、webページにjavascriptを追加してテンプレートに沿って表示させています。ページ送りをするためには、java、tpl、phpのどのプログラムを変更すればいいのかもわかりません。ご指導お願い致します。

お礼日時:2008/07/27 12:53

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!