Pagination. Page shows even if page number exceeds last page.

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(






$this->widget('CLinkPager', array(



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)

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.