YII框架中搜索分頁jQuery寫法詳解
更新時(shí)間:2016年12月19日 10:59:03 作者:CZY_1214
這篇文章主要介紹了YII框架中搜索分頁jQuery寫法詳解的相關(guān)資料,需非常不錯(cuò),具有參考借鑒價(jià)值,要的朋友可以參考下
控制層
use frontend\models\StudUser; use yii\data\Pagination; use yii\db\Query; /** * 查詢 * */ public function actionSearch() { //接值 $where=Yii::$app->request->get(); //實(shí)例化query $query=new Query(); $query->from('stud_user'); //判斷 if(isset($where['sex'])&&$where['sex']!=''){ //判斷 if($where['sex']=='男'){ $query->andWhere(['stud_sex'=>0]); } if($where['sex']=='女'){ $query->andWhere(['stud_sex'=>1]); } }else{ $where['sex']=''; } //年齡 if(isset($where['age'])&&$where['age']!=''){ $query->andWhere(['>','stud_age',$where['age']]); }else{ $where['age']=''; } //分頁 $pagination = new Pagination(['totalCount' => $query->count()]); //條數(shù) $pagination->setPageSize('3'); //條件 $query->offset($pagination->offset)->limit($pagination->limit); //執(zhí)行 $userInfo=$query->all(); //print_r($userInfo);die; return $this->render('search',['userInfo'=>$userInfo,'page'=>$pagination,'where'=>$where]); }
模型層
<?php namespace frontend\models; use Yii; use yii\db\ActiveRecord; class StudUser extends ActiveRecord { /** * 聲明表名 * */ public static function tableName() { return '{{%stud_user}}'; } /** * 驗(yàn)證規(guī)則 * */ public function rules() { return [ ['stud_age','integer'], ]; } }
視圖層
<?php use yii\widgets\ActiveForm; use yii\helpers\Url; use yii\helpers\Html; use yii\widgets\LinkPager; ?> <?php $form=ActiveForm::begin([ 'action'=>Url::toRoute(['admin/search']), 'method'=>'get', ]); echo '性別'," ",Html::input('text','sex',$where['sex']); echo '年齡'," ",Html::input('text','age',$where['age']); echo Html::submitButton('提交'); ActiveForm::end(); ?> <table class="table"> <tr> <td>序號</td> <td>姓名</td> <td>年齡</td> </tr> <?php foreach($userInfo as $val):?> <tr> <td><?= $val['stud_id']?></td> <td><?= $val['stud_name']?></td> <td><?= $val['stud_age']?></td> </tr> <?php endforeach;?> </table> <?php echo LinkPager::widget([ 'pagination' => $page, 'nextPageLabel'=>'下一頁' ]);?>
分頁的樣式在
LinkPager.php中
以上所述是小編給大家介紹的YII框架中搜索分頁jQuery寫法詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- Yii框架分頁實(shí)現(xiàn)方法詳解
- Yii框架結(jié)合sphinx,Ajax實(shí)現(xiàn)搜索分頁功能示例
- yii框架搜索分頁modle寫法
- Yii框架引入coreseek分頁功能示例
- yii框架使用分頁的方法分析
- Yii分頁用法實(shí)例詳解
- Yii使用CLinkPager分頁實(shí)例詳解
- Yii2分頁的使用及其擴(kuò)展方法詳解
- Yii列表定義與使用分頁方法小結(jié)(3種方法)
- yii2分頁之實(shí)現(xiàn)跳轉(zhuǎn)到具體某頁的實(shí)例代碼
- yii2實(shí)現(xiàn)分頁,帶搜索的分頁功能示例
- Yii框架分頁技術(shù)實(shí)例分析
相關(guān)文章
thinkphp 框架數(shù)據(jù)庫切換實(shí)現(xiàn)方法分析
這篇文章主要介紹了thinkphp 框架數(shù)據(jù)庫切換實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkphp 框架數(shù)據(jù)庫切換實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05Thinkphp 框架擴(kuò)展之標(biāo)簽庫驅(qū)動原理與用法分析
這篇文章主要介紹了Thinkphp 框架擴(kuò)展之標(biāo)簽庫驅(qū)動,結(jié)合實(shí)例形式分析了Thinkphp標(biāo)簽庫驅(qū)動擴(kuò)展相關(guān)概念、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04淺談laravel中的關(guān)聯(lián)查詢with的問題
今天小編就為大家分享一篇淺談laravel中的關(guān)聯(lián)查詢with的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10