0
votes

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

    }

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
What happens if you make a request to http://mydomain/search?pg_number=5 ?Jeff Lambert
@watcher when request is made to the above link data view is loaded through ajax,all content loaded by ajax is fine except pagination which don't update the active link.Adnan Tahir Hashmi

2 Answers

1
votes

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.

0
votes

In the Paginator::make() methos the first parameter is an array of items that are already paginated. Check this example:

    $perPage = 15;
    $currentPage = Input::get('page', 1) - 1;
    $pagedData = array_slice($items, $currentPage * $perPage, $perPage);
    $matches = Paginator::make($pagedData, count($items), $perPage);

In this example I use the array_slice methos to get the items of the current page. To get the page in your controller you can use Input::get('page', 1) so if there is no page selected to default would be 1