Yii Framework Forum: Pagination. Page shows even if page number exceeds last page. - Yii Framework Forum

Jump to content

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

Pagination. Page shows even if page number exceeds last page. how to get 404 error if page number exceeds last page number Rate Topic: -----

#1 User is offline   mcast 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 10-June 09

  Posted 26 October 2010 - 06:17 AM

I have problem. When I use pagination and, for example if last page number is 7, and if I am trying to open page 12, it opens last page with number 7. But I would like to show 404 error in such cases.
Are there any solution in Yii or I should do it by myself (check if page number exceeds last page number)?

I use simple code:
$dataProvider = new ActiveDataProvider('Post', array(
	'criteria'=>$mycriteria,
	'pagination'=>array(
	'pageSize'=>10,
	'pageVar'=>'page',
)));

$this->widget('CLinkPager', array(
    'pages'=>$dataProvider->pagination,
));

0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,349
  • Joined: 12-October 09
  • Location:Croatia

Posted 26 October 2010 - 06:29 AM

As per current implementation if the page is bigger than the pageCount()... the current page is set to the last page if validateCurrentPage is set to true (default)

http://yiiframework....rentPage-detail

If you set validateCurrentPage to false the current page will not change... but I'm not sure how that will reflect in your code...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   mcast 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 10-June 09

Posted 01 November 2010 - 05:51 AM

View Postmdomba, on 26 October 2010 - 06:29 AM, said:

As per current implementation if the page is bigger than the pageCount()... the current page is set to the last page if validateCurrentPage is set to true (default)

http://yiiframework....rentPage-detail

If you set validateCurrentPage to false the current page will not change... but I'm not sure how that will reflect in your code...


I need to check current page number because I use caching with varyByParam=array('page'). My cache depends on page number. When page number exceeds total page number, new cache item will be created. It is dangerous, because if somebody will be doing infinite HTTP accesses to my site with different page numbers, I will get infinite number of cached items. And my server will crash.
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