【发布时间】:2014-08-19 11:17:26
【问题描述】:
我是 laravel4 的新手,我基本上是在 laravel 4 中使用 Nusoap 库处理 SOAP Web 服务。
我的问题是分页,在控制器上我的代码是 ast follow
function AjaxProductList()
{
$isAjax = Request::ajax();
if($isAjax)
{
//instantiate the NuSOAP class and define the web service URL:
$client = new nusoap_client('http://stage.ws.greenbook.net/gbwswcf/servicegb.svc?wsdl', 'WSDL');
//check if there were any instantiation errors, and if so stop execution with an error message:
$error = $client->getError();
if ($error) {
die("client construction error: {$error}\n");
}
if(Input::get('term'))
{
Session::put('term', Input::get('term'));
$term = Input::get('term');
}
else
$term = Session::get('term');
if(Input::get('pg_number')!='')
{
Session::put('page_num', Input::get('pg_number'));
$page_num = Input::get('pg_number');
}
else
$page_num = Session::get('page_num');
if(Input::get('per_pg_result') !='')
{
Session::put('result_per_page', Input::get('per_pg_result'));
$result_per_page = Input::get('per_pg_result');
}
else
$result_per_page = Session::get('result_per_page');
$param = 'SearchParam=|category@'.Session::get('type').'|searchterm@'.$term;
//$value = Session::get('key');
$params = array( 'ClientID' => Config::get('globals.ClientID'),
'strPwd' => Config::get('globals.password'),
'Params' => $param ,
'PageNum' =>$page_num,
'NumOfResultsPerPage' =>$result_per_page
);
$client->soap_defencoding = 'UTF-8';
$answer = $client->call('GetResultsV2',$params);
//check if there were any call errors, and if so stop execution with some error messages:
$error = $client->getError();
if ($error) {
echo 'some error occured , please try again later';
die();
}
$ResultNumbers = Common::find_key_array('ResultNumbers',$answer);
$data['SearchParams'] = Common::find_key_array('SearchParams',$answer);
$data['products'] = Common::find_key_array('Product',$answer);
$data['total_result'] = $ResultNumbers['TotalNum'];
$data['paginator'] = **Paginator::make($data['products'],$data['total_result'],$result_per_page)**;
$return["prd_listing_bot"] = View::make('frontend.search.ajax_product_listing',$data)->render();
echo json_encode($return);
exit;
}
else
{
echo 'not allowed';
}
}
这里我使用 Paginatior 类并提供参数(返回记录、总项目、每页项目)。
这是我的视图代码:
$paginator->setBaseUrl('search');
echo $paginator->links();
现在它已成功创建链接
点击5后我的网址结构是
'http://mydomain/search?page=5'.
在 'routes.php' 我有
Route::any('search', array('uses' => 'SearchController@QuickSearch'));
当加载页面视图时,会为函数 AjaxProductList() 发起 ajax 调用;
当我点击分页中的任何链接时,它会成功获取数据,但不会更新活动链接。即,如果我单击第 5 页,它将获取正确的数据,但活动链接仍将位于第“1”页。
如果我做错了什么请告诉我?
提前致谢。
【问题讨论】:
-
如果您向
http://mydomain/search?pg_number=5发出请求会怎样? -
@watcher 当请求通过 ajax 加载上述链接数据视图时,所有由 ajax 加载的内容都很好,除了不更新活动链接的分页。
标签: php jquery ajax laravel pagination