Yii Framework Forum: Pagination inside pages - Yii Framework Forum

Jump to content

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

Pagination inside pages using CLinkpager and mating urlrules

#1 User is offline   smoothcoder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 03-December 09
  • Location:Thailand

Posted 22 January 2010 - 01:33 PM

I recently had to publish on DISCARDEDteenz.com 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

PageController.php
 public function actionShow()
    {
	$model=$this->loadPageSlug();
        $this->pageTitle=$model->title;

	if (isset($_GET['page']))
		$section=$_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);
	
	$sections->setCurrentPage($section-1);
	$this->render('show',array('model'=>$model,'pages'=>$sections));
    }



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 ! :-)

this is because I have urlrules with:
'page/<slug:[a-z0-9-]+>*'=>'page/show',



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:
http://www.yiiframew...oc/cookbook/53/
http://www.yiiframew...amed-parameters
1

#2 User is offline   Mrsome1 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-March 10

Posted 20 March 2010 - 01:42 PM

Could you please explain it step by step?
0

#3 User is offline   Mrsome1 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-March 10

Posted 20 March 2010 - 01:43 PM

Could you please explain it step by step?
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