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 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来