Getting Page Number From Dataprovider

I need a pagination variable from my dataprovider in my controller action :

1.Current Page Number

How to get it ?

Hi,

You are getting in the URL itself… check my url

http://localhost/WB/Pho/phoperson/admin/ajax/pho-person-grid/PhoPerson_page/3?ajax=pho-person-grid^

here 3 represent 3 page in my gridview

2 for 2nd page :)

Hi,

I can see it in url. How to get that in a variable from the dataprovider ?

Please can you tell me what are you trying to achieve. maybe it can help to check myself

I am trying to display the page number in the title of my page

Hi,

you can get your current page number in controller inside actionadmin method using

following code

$_GET[‘Programm_page’])

modelname_page … in above case my model name is programm

Hi Chandran,

I thought the same way. Because my link showed like this :

www.xxxx.com/hello/index?Controller_page=4&ajax=ywo

But when I tried to use($_GET[Controller_page]) , its always null. Is it because I am using ajax for it ? If yes, how to get the page number for ajax ?

Hi,

i am using CGridview …

[color="#0000ee"]xxxxx/WB/programm/admin?Programm_page=4&ajax=programm-grid[/color]

[color="#0000ee"][u]

[/u][/color][color="#222222"][font="Consolas,"]my url also having same thing what you have … but i can access the Programm_page[/font][/color]

[color="#222222"][font="Consolas,"]

[/font][/color]are you using CGridview or Clistview ?

$_GET[Controller_page]

I think u r mising quotes

$_GET[‘Controller_page’]

:)

I did not miss the quotes inside my code. I am using ListView.

This is what I tried :




$page = isset($_GET['Controller_page']) ? $_GET['Controller_page'] : "hello";

		

echo "pagenumber".$page;



It always prints hello

Hi Chandran,

I tried disabling the ajaxUpdate by setting it to false and now its working. But I want to make it work with ajax ? Any idea ?

Hi,

please can you copy your clistview code here … including ajax call




 $this->widget('zii.widgets.CListView', array(

		'dataProvider'=>$dataProvider,

		'itemView'=>'//hello/_zoomview',

		'ajaxUpdate'=>false,                  //Not working if i remove this

		'enablePagination'=>true,

		'summaryText'=>'',

		'tagName'=>'div',

		'itemsTagName'=>'ul',

		'itemsCssClass'=>'hello-preview ',

		'htmlOptions'=> array(

			'class'=>'hello-preview'

		),

		'pager'=>array(

			'header'=>"",

		),

		'afterAjaxUpdate'=>'function(id,data){ $(\'div.star-rating-holder input \').rating({\'readOnly\':true}); hellohover();}',	

	)); 



For your information,

cgridview and clistview are working using ajax…

Try it like this… below code is reference for getting value in controller

Do you mean the page number is getting printed in listview ajax also ?

This is my controller for your reference :







$page = isset($_GET['Hello_page']) ? $_GET['Hello_page'] : "hello";

		

		

		// build criteria object based on params

		$criteria = Hello::buildCriteria($keyword,$direction);

		// create dataProvider for result

		$dataProvider = new CActiveDataProvider(			 

			'Hello',

			array(

				'criteria'=>$criteria,

				'pagination'=>array(					

					'pageSize'=>20

				),

			)

		);


$this->render('//hello/index',array(

			'dataProvider'=>$dataProvider));




Hello is my controller name

Hi,

This is my code… its working perfect

In controller





/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		if(isset($_GET['PhoOrganisation_page']))

			print_r($_GET['PhoOrganisation_page']);

		$dataProvider=new CActiveDataProvider('PhoOrganisation',

				array('pagination'=>array(

						'pageSize'=>2

					),

				)

		);

		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}



In view





<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); ?>



hello uwaisfariz getting current page number is easiest one lets me assume that $dataProvider is an cactivedataprovider’s object and you can get the current page number like this




$currrent_page = $dataProvider->getPagination()->currentPage;

echo $current_page;



note : current page is an zero based index so to print the human readable page number please add 1 to $current_page

Can you tell me what is the url you are getting when you go to second page via ajax ?

I tried it. Current Page value not getting changed.

what happened? how many pages you have?

I have around 10 pages. You can see my controller and view above. Using the method chandran suggested, it works if i disable ajax. Because the url gets changed to www.xxx.com/hello/index?Hello_page=3 and $_GET gets the value. With ajax, its not working. The reason for it is because my url remains same for all the pages (www.xxx.com/hello/index). So $_GET will be null.