droc60607 2014-08-19 11:17
浏览 48
已采纳

分页Laravel 4不会更新活动页码

I am new to laravel4, I am working basically with SOAP webservices in laravel 4 using Nusoap library.

My problem is with pagination, at controller my code is 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}
");
              }


                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'; 
         } 

    }

here i am using Paginatior class and providing the parameters (returned records,total items,perpage items).

here is my view code:

$paginator->setBaseUrl('search');
echo $paginator->links();

NOW its creating links successfully

My URL structure after clicking 5 is

 'http://mydomain/search?page=5'.

and in 'routes.php' i have

Route::any('search', array('uses' => 'SearchController@QuickSearch'));

when the page view is loaded an ajax call is initiated for function AjaxProductList();

when i click on any link in pagination, it fatches data successfully, but not updating the active link. i.e if i click on page number 5 it will fetch the correct data but active link will be still at page "1".

tell me please if i am doing anything wrong?

thanks in advance.

  • 写回答

2条回答 默认 最新

  • drmqzb5063 2014-08-21 11:41
    关注

    Just solved it by placing

    Paginator::setCurrentPage($page_num);
    

    above the line

    Paginator::make($data['products'],$data['total_result'],$result_per_page);
    

    Anyway thanks to everyone who participated here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下