Pagination inside pages

I recently had to publish on each chapter of my daughter’s book. I decided to create a Page (with a model) to do that. Soon after putting it online, I had complains from relatives (I will not tell who) B) that the page was too long. Mmm ? I decided to use a widget CLinkPager to manage this.

The thing is I had to cut one page into sections and make CLinkPager think that the section had a model.I also had to put some delimiters inside the original text . I used <!–leaf–> .

This works: You can see it there on chapter1


 public function actionShow()




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


	else $section=1;

	// I have placed some page markers <!--leaf--> in the page content

	$leaves=array(); $leaves=explode('<!--leaf-->',$model->content); 


	$sections=new CPagination(sizeof($leaves));$sections->pageSize=1;

	$sections->applyLimit($criteria=new CDbCriteria);





So now instead of echoing the whole page ( $model->content) I have now in views/page/show.php



	$leaves=array(); $leaves=explode('<!--leaf-->',$model->content);  

	// checking where am I in the page

	echo "section=".($pages->getCurrentPage()+1)  .'/'.sizeof($leaves) ;

	//now displaying only one section

		echo $leaves[$pages->getCurrentPage()]; 

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


Maybe somebody can tell me how to avoid repeat the “explode” ? :unsure:

Now in my browser:If I write

"myserver/page/chapter1/page/1" I display section one

"myserver/page/chapter1/page/2" I display section two etc. Good ! :slight_smile:

this is because I have urlrules with:


I can even see the widget and it’s on the right section (setCurrentPage works fine):

Go to page: * << First * < Previous * 1 * 2 * 3 * 4 * 5 * 6 * Next >

I had some problems with the urls from CLinkPager which were not following my urlmanager rules:

It was displaying:

myserver/page/chapter1?page=5&section=4 on the link 5

But that was solved because I discovered the power of the "star" character in the urlrules.

The _GET variable was back!

So now I know that I can use CLinkPager even if I don’t have a model. Was there a better way to do this ? $sections->applyLimit($criteria=new CDbCriteria);

This helped me a lot to solve this case:

Could you please explain it step by step?

Could you please explain it step by step?