Yii Framework Forum: Where to set default pagesize? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Where to set default pagesize? Rate Topic: -----

#1 User is offline   plm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 13-January 12
  • Location:Switzerland

Posted 13 January 2012 - 04:51 PM

Hi guys

I'm new here so be gentle ;)!
After using yii for quite some time i know it quite good already.

Directly to my question: Is there a way to set the default pagesize (eg for CGridView) in the main app config (/protected/config/main.php)!? If so...how would i do it?

I'm aware of that i can set the value in the model via a public param of the config like so:
public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('iso_code_number',$this->iso_code_number,true);
		$criteria->compare('iso_code',$this->iso_code,true);
		$criteria->compare('identifier',$this->identifier,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('changed',$this->changed,true);
		$criteria->compare('changed_by',$this->changed_by,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
				[b]'pageSize'=>Yii::app()->params['defaultPageSize'],[/b]		
			),
		));
	}


But I'm looking for a cleaner way to set this value globally in the config without having to touch each model. I found no such solution on the web or in this forum...


thanks already in advance,
pascal
0

#2 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 14 January 2012 - 06:17 AM

http://www.yiiframew...1.1/CPagination, CPagination is the class that controls CDataProvider instances with page size etc. The thing is, CGridView doesn't actually control page sizes, that's the CDataProvider's job.

So here are some of your options:

1. Edit CPagination (Yuck!)
2. Extend CPagination and have your version pull the data out of config. Then set it as the pagination object for CActiveDataProvider with the setPagination() method. You could even extend CActiveDataProvider so it used your Pagination class as it's default Pagination object.
3. Keep doing it the way you are doing it now.
0

#3 User is offline   plm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 13-January 12
  • Location:Switzerland

Posted 15 January 2012 - 03:20 PM

View PostLuke Jurgs, on 14 January 2012 - 06:17 AM, said:

http://www.yiiframew...1.1/CPagination, CPagination is the class that controls CDataProvider instances with page size etc. The thing is, CGridView doesn't actually control page sizes, that's the CDataProvider's job.

So here are some of your options:

1. Edit CPagination (Yuck!)
2. Extend CPagination and have your version pull the data out of config. Then set it as the pagination object for CActiveDataProvider with the setPagination() method. You could even extend CActiveDataProvider so it used your Pagination class as it's default Pagination object.
3. Keep doing it the way you are doing it now.


Hi Luke

Thanks a lot for your answer. Option 1 really is no option ;)! Hmm good idea...no clue why i thought about that after deriving a lot of other classes already :D!

Thanks a lot for your time!
0

#4 User is offline   egulhan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-May 12

Posted 20 April 2013 - 12:52 PM

View Postplm, on 15 January 2012 - 03:20 PM, said:

Hi Luke

Thanks a lot for your answer. Option 1 really is no option ;)! Hmm good idea...no clue why i thought about that after deriving a lot of other classes already :D!

Thanks a lot for your time!


"Yii => custom WidgetFactory, adds onBeforeCreateWidget, onAfterCreateWidget events. An example of how the custom class can be used has been provided as well, in the process solving a typical Yii issue, regarding how to set the default pagesize for widgets that use dataproviders (due to dataproviders initializing pagination, by which widget pager settings are typically ignored)."

https://gist.github....ntel352/4513672
Php web deleloper
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users