Home >php教程 >PHP开发 >Yii view operation custom paging implementation method

Yii view operation custom paging implementation method

高洛峰
高洛峰Original
2016-12-30 16:11:101636browse

The example in this article describes the custom paging implementation method of Yii view operation. Share it with everyone for your reference, the details are as follows:

1. When the view file calls cgridview, clistview, call the custom paging method

<?php $this->widget(&#39;zii.widgets.grid.CGridView&#39;, array(
 &#39;id&#39;=>&#39;news-grid&#39;,
 &#39;dataProvider&#39;=>$model->search(),
 &#39;filter&#39;=>$model,
 &#39;template&#39;=>&#39;{items}{summary}{pager}&#39;,
  &#39;selectableRows&#39;=>2,
  &#39;pager&#39;=>&#39;ZPager&#39;,
  &#39;summaryText&#39;=>&#39;页数:{pages}/{page}页&#39;,
  &#39;columns&#39;=>array(
  array(
   &#39;class&#39;=>&#39;CCheckBoxColumn&#39;,
   &#39;footer&#39;=>&#39;<button onclink="deleteAll()">button</button>
      <button onclink="refashAll()">button</button>&#39;,
   &#39;footerHtmlOptions&#39;=>array(&#39;colspan&#39;=>5),
   &#39;selectableRows&#39;=>2,
  ),
  &#39;id&#39;,
  array(&#39;name&#39;=>&#39;title&#39;,
    &#39;htmlOptions&#39;=>array(&#39;width&#39;=>&#39;20%&#39;),
    &#39;value&#39;=>&#39;mb_substr($data->title,0,10,"utf-8")&#39;,
   ),
  array(&#39;name&#39;=>&#39;content&#39;,
    &#39;htmlOptions&#39;=>array(&#39;width&#39;=>&#39;20%&#39;),
    &#39;value&#39;=>&#39;mb_substr(strip_tags($data->content),0,10,"utf-8")&#39;,
   ),
  array(&#39;name&#39;=>&#39;type&#39;,
    &#39;value&#39;=>&#39;News::model()->getNewsType($data->type)&#39;,
   ),
  &#39;user&#39;,
  array(&#39;name&#39;=>&#39;status&#39;,
    &#39;value&#39;=>&#39;News::model()->getNewsStatus($data->status)&#39;,
    ),
  array(
   &#39;class&#39;=>&#39;CButtonColumn&#39;,
   &#39;buttons&#39;=>array(
    &#39;view&#39;=>array(&#39;visible&#39;=>&#39;false&#39;),
    //&#39;delete&#39;=>array(&#39;click&#39;=>&#39;true&#39;),
   ),
  ),
 ),
));

2. Copy the base paging class file and modify it to become Copy your own paging method

framework/web/widgets/pagers/CListPager.php and rename it to protected/components/zpager.php. Modify the class name

framework/web/widgets/pagers/ pager.css Copy the corresponding style file to protected/components/css/pager.css

Modify the css loading directory of zpager.php

public static function registerCssFile($url=null)
{
 if($url===null)
  $url=CHtml::asset(Yii::getPathOfAlias(&#39;application.components.css.pager&#39;).&#39;.css&#39;);
 Yii::app()->getClientScript()->registerCssFile($url);
}

3. By modifying the Css style file, you can also modify the generated List program to achieve the purpose of modifying classification.

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

For more articles related to Yii view operation custom paging implementation methods, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn