I do in action so

$dataProvider = new CSqlDataProvider($sql, array( 'totalItemCount' => $count, 'pagination'=>array( 'pageSize'=>8, //'pageVar'=>'page', //'route'=>'/', ), )); 

then pass to the template, and call the widget

 $this->widget('zii.widgets.CListView', array( 'dataProvider'=>$dataProvider, 'itemView'=>'row', 'template'=> "{pager}\n{items}\n{pager}", 'pager'=>array( 'maxButtonCount' => '10', 'prevPageLabel'=>'←', 'nextPageLabel'=>'→', 'header'=>'Навигация: ', ), 'ajaxUpdate'=>false, )); 

everything would be fine, but links are generated by site.ru/my/patch?page=2 , I want to change to links of this type site.ru/my/patch/page_2.html how to do this? And are there any ways to change the very html structure of the paginator without problems?

  • Well, where is the pattern? - Artem
  • In terms of where the pattern? Yii itself generates a template for the paginator, you can certainly climb into the core of the framework, but I do not think that this is correct. - tranceman
  • Then most likely to you in htaccess and there configure to make the URL normal. and there to make a URL like site.ru/my/patch/page/2 or in the settings Yii 'urlManager' => array ('urlFormat' => 'path', - Artem
  • There are no problems with this, the problem is that the widget does not generate the correct links, or rather not the type that I need - tranceman
  • stop, and why is it so important to do so page_2.html why is it not convenient for you? page = 2 this record? I woke up something recently and did not eat yet. it adds a gett parameter to the url and everything is fine. - Artem

2 answers 2

Duc can then do everything differently.

There is some kind of controller.

Let's say you have my

  public function actionSome() { // выборка из таблицы $criteria = new CDbCriteria; $pagination = new CPagination(MODELKAKAYATO::model()->count($criteria)); $pagination->pageSize = 5; // количество записей на странице $pagination->applyLimit($criteria); $result = MODELKAKAYATO::model()->findAll($criteria); // рендерим $this->render('blablabla', array( 'res'=>$result , 'pagination'=>$pagination )); 

Well, render this render (blablabla).

 <?php foreach($result as $r) : ?> <div><?php $r->title ?> - <?php $r->code ?></div> <?php endforeach ?> // ну а тут думай как лучше тебе сделать вывод своего пагинатора, но уи учитывай как контроллер будет его обрабатывать !!! <? $this->widget('CLinkPager',array( 'pages'=>$pagination, )) ?> 

Well, deduce as you need.

It's just that Yii does his paginator correctly in essence, it’s not worth rewriting his conclusion, for he is the core.

But to make as if “your” paginator is a bicycle, but sometimes you have to pervert even with such frameworks.

I think it helped :)

  • I just wanted to avoid this) There, in the settings, if you play with PageVar, route, you can change the URL, but since I need it, it didn’t work and I couldn’t find a normal example, only a couple of lines in the English documentation. And with the html structure is not critical, just for the sake of interest asked) - tranceman
  • Well, maybe it can be avoided, but I still can’t tell you how, because I haven’t encountered such a task in my practice, but if this rake helps, it’s good. @tranceman, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). :) - Artem

1. I think the url generation can be changed using routers.

2. And what prevents to stylize buttons as an example: http://media.vashmir.by/filter/year/59.html?page=7

If you want, I can take the time and help sort it all out.