More flexibility to pagination

I’m beginning to love Yii for the easily extensible design, but I see there is more to be desired.

Today I thought I needed a paged CGridView that starts by default on the last page instead of the first. This should be easy by extending the CPagination component and overriding the getCurrentPage() method to set _currentPage to getPageCount()-1 instead of 0 when no specific page is requested in $_GET.

Two more things needed changing though:

  • In CPagination _current_page is defined as private instead of protected. Generally any property that might be of interest to a descendant class should be defined as protected and not private.

  • The createPageUrl() method of CPagination does not add the page number to the first page url. Commenting out two lines of code solved this.

I hope these two small changes could be included in the official version.

I agree that class variables shouldn’t usually be private, and this is something that is quite common in a lot of Yii classes.