本文实例讲述了Yii框架分页实现方法。分享给大家供大家参考,具体如下:
下家公司用的框架是yii,这几天看了下相关教程,今儿把分页教程写下,最后把tp的分页也给整合进了yii,因为个人觉得yii分页没有tp用的顺手。
首页,在models目录里创建个Auth.php的模型文件,里面写入
class Auth extends CActiveRecord { public static function model($className = __CLASS__) { return parent::model($className); } public function tableName() { return '{{auth}}'; } }
接着在controllers目录里创建IndexController.php的控制文件,里面写入
class IndexController extends Controller { public function actionList() { $criteria = new CDbCriteria(); $criteria->order = 'a_id desc'; $count = Auth::model()->count($criteria); $page = new CPagination($count); $page->pageSize = 10; $page->applyLimit($criteria); $auth = Auth::model()->findAll($criteria); $this->renderPartial('auth', array('page' => $page, 'list' => $auth)); } public function actionList1() { $p = isset($_GET['page']) "a_id,a_nickname"; $criteria->condition=''; $criteria->limit = 10; $criteria->offset = $p == 0 "htmlcode"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <div class="blogList"> <ul> <"page"> <"htmlcode">$this->varPage = C('VAR_PAGE') "htmlcode">$this->varPage = 'p' ;改完之后,这个两个文件是不需要引入的,因为yii在启动时会自动加载的。具体的可见protected/config.php/main.php的配置中的
// autoloading model and component classes 'import'=>array( 'application.models.*', 'application.components.*', ),其次,在protected/config.php/目录里新建一个common.php文件,这个文件就放些项目的公共函数,熟悉tp的朋友应该知道tp也有公共函数文件,很好用,这里借鉴下,yii应该也有吧,目前还没发现。在该文件写入
// 根据页码获取列表 function getListByPage($model, $select = '*', $condition = '', $limit = 10, $order = '', $p = '', $ajax = 0) { // 初始化参数 $_GET['p'] = isset($_GET['p']) "htmlcode">require_once(dirname($config) . '/common.php');最后在indexController.php中用到分页的地方调用该方法
public function actionPage() { $model = Auth::model(); $info = getListByPage($model); $this->renderPartial('page', array('info' => $info)); }封装了此方法,以后调用分页时,只需传几个参数,简单又快捷。在page.php页面上调用
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <div class="blogList"> <ul> <"page"> <"htmlcode">function getListByPage($model, $select = '*', $condition = '', $limit = 10, $order = '', $p = '', $ajax = 0) { if (!$model) { return array();; } // 初始化参数 $_GET['p'] = isset($_GET['p']) "_blank" href="https://www.jb51.net/Special/386.htm">Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
华山资源网 Design By www.eoogi.com广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!华山资源网 Design By www.eoogi.com暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】