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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘