Yii框架引入coreseek分頁(yè)功能示例
本文實(shí)例講述了Yii框架引入coreseek分頁(yè)功能。分享給大家供大家參考,具體如下:
把sphinxapi.php改為SphinxClient.php 類(lèi)文件隨便放,你能找到就行,我放在advanced/frontend/web/SphinxClient.php,打開(kāi)common/config/bootstrap.php
在里面添加
Yii::$classMap['SphinxClient']='@frontend/web/SphinxClient.php';
地址寫(xiě)正確
在需要用得控制其中 use SphinxClient
controller控制器
/** * 話題搜索 * * @author YING * @param void * @return void */ public function actionTopic() { //模擬數(shù)據(jù) $studId=2; //用戶id $classId=2; //班級(jí)id $title=""; //為空 //實(shí)例化模型 $studTopic=new StudTopic(); //查詢 $data=$studTopic->find()->select('*')->innerJoin('stud_user','stud_topic.stud_id=stud_user.stud_id')->where(['class_id'=>$classId]); //實(shí)例化分頁(yè)類(lèi) $pagination=new Pagination(['totalCount' => $data->count()]); //每頁(yè)條數(shù) $pagination->setPageSize(3); //執(zhí)行分頁(yè) $topicInfo= $data->offset($pagination->offset)->limit($pagination->limit)->asArray()->all(); //返回值 return $this->render('topicList',['topicInfo'=>$topicInfo,'pages'=>$pagination,'studId'=>$studId,'classId'=>$classId,'title'=>$title]); } /** * coreseek搜索 * * @author YING * @param void * @return void */ public function actionSearchTitle() { //接值 $title=Yii::$app->request->get('t_title'); $classId=Yii::$app->request->get('class_id'); //模擬數(shù)據(jù) $studId=2; //用戶id //coreseek 搜索 $cl = new SphinxClient (); $cl->SetServer ( '127.0.0.1', 9312); $cl->SetConnectTimeout ( 3 ); $cl->SetArrayResult ( true ); $cl->SetMatchMode ( SPH_MATCH_ANY); $res = $cl->Query ( $title, "*" ); //如果存在值 if($res['total']){ $matches=$res['matches']; foreach($matches as $key => $val){ $tidArray[]=$val['id']; } } //轉(zhuǎn)化為字符串 $tidStr=isset($tidArray) ? implode(',',$tidArray) : 0; //實(shí)例化模型 $studTopic=new StudTopic(); //查詢 $data=$studTopic->find()->select('*')->innerJoin('stud_user','stud_topic.stud_id=stud_user.stud_id')->where("t_id in ($tidStr)"); //實(shí)例化分頁(yè)類(lèi) $pagination=new Pagination(['totalCount' => $data->count()]); //每頁(yè)條數(shù) $pagination->setPageSize(3); //執(zhí)行分頁(yè) $topicInfo= $data->offset($pagination->offset)->limit($pagination->limit)->asArray()->all(); //加載模板 return $this->render('topicList',['topicInfo'=>$topicInfo,'pages'=>$pagination,'studId'=>$studId,'classId'=>$classId,'title'=>$title]); }
view視圖
<?php use yii\widgets\ActiveForm; use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\LinkPager; ?> <table class="table"> <tr> <td>標(biāo)題</td> <td>作者</td> <td>發(fā)布時(shí)間</td> <td>操作</td> </tr> <?php foreach($topicInfo as $key => $val): ?> <tr id="tr_<?= $val['t_id']?>"> <td><input type="checkbox" tid="<?= $val['t_id']?>"/> <?= $val['t_title']?></td> <td><?= $val['stud_name']?></td> <td><?= date('Y-m-d H:i:s',$val['add_time'])?></td> <?php if($val['stud_id']==$studId):?> <td><a href="index.php?r=student/update-topic&topic_id=<?= $val['t_id']?>" rel="external nofollow" >編輯</a>||<a href="">刪除</a></td> <?php else: ?> <td><a href="">刪除</a></td> <?php endif; ?> </tr> <?php endforeach; ?> <tr> <td><input type="button" value="全選/全不選" id="all"/></td> <td><input type="button" value="反選" id="fan"/></td> <td><input type="button" value="批刪" id="del"/></td> </tr> </table> <?php echo LinkPager::widget([ 'pagination' => $pages, ]); ?> <script src="./css/js/jquery.1.12.min.js"></script> <script> //全選/全不選 var temp=true; //臨時(shí)變量 $('#all').click(function(){ $('input[type="checkbox"]').prop('checked',temp); //取反 temp=!temp; }) //批刪 $('#del').click(function(){ var checkAll=$('input[type="checkbox"]'); //獲取全部的復(fù)選框 var length=checkAll.length; //計(jì)算長(zhǎng)度 var arr=new Array(); //定義數(shù)組 var str=""; //定義字符串 //循環(huán) $.each(checkAll,function(k,v){ //判斷是否選中 if(checkAll[k].checked){ arr.push(checkAll.eq(k).attr('tid')); } }) //轉(zhuǎn)化為字符串 str=arr.join(','); //ajax var url="index.php?r=student/delete-all"; //地址 $.get(url,{str:str},function(msg){ if(msg){ //window.location.reload(); //刷新頁(yè)面 //節(jié)點(diǎn)刪除 $.each(arr,function(k,v){ $('#tr_'+v).remove(); }); } },'json'); }); //反選 $("#fan").click(function(){ var checkAll=$('input[type="checkbox"]'); //獲取復(fù)選 $.each(checkAll,function(k,v){ this.checked=!this.checked; }) }); </script>
搞定 收工 ok!
更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Yii框架入門(mén)及常用技巧總結(jié)》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《smarty模板入門(mén)基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
- Yii框架分頁(yè)實(shí)現(xiàn)方法詳解
- Yii框架結(jié)合sphinx,Ajax實(shí)現(xiàn)搜索分頁(yè)功能示例
- YII框架中搜索分頁(yè)jQuery寫(xiě)法詳解
- yii框架搜索分頁(yè)modle寫(xiě)法
- yii框架使用分頁(yè)的方法分析
- Yii分頁(yè)用法實(shí)例詳解
- Yii使用CLinkPager分頁(yè)實(shí)例詳解
- Yii2分頁(yè)的使用及其擴(kuò)展方法詳解
- Yii列表定義與使用分頁(yè)方法小結(jié)(3種方法)
- yii2分頁(yè)之實(shí)現(xiàn)跳轉(zhuǎn)到具體某頁(yè)的實(shí)例代碼
- yii2實(shí)現(xiàn)分頁(yè),帶搜索的分頁(yè)功能示例
- Yii框架分頁(yè)技術(shù)實(shí)例分析
相關(guān)文章
PHP下 Mongodb 連接遠(yuǎn)程數(shù)據(jù)庫(kù)的實(shí)例代碼
這篇文章主要介紹了PHP下 Mongodb 連接遠(yuǎn)程數(shù)據(jù)庫(kù)的實(shí)例代碼,需要的朋友可以參考下2017-08-08PHP+memcache實(shí)現(xiàn)消息隊(duì)列案例分享
現(xiàn)在memcache在服務(wù)器緩存應(yīng)用比較廣泛,下面我來(lái)介紹memcache實(shí)現(xiàn)消息隊(duì)列等待的一個(gè)例子,有需要了解的朋友可參考。2014-05-05yii2-GridView在開(kāi)發(fā)中常用的功能及技巧總結(jié)
本篇文章主要介紹了yii2-GridView在開(kāi)發(fā)中常用的功能及技巧總結(jié),數(shù)據(jù)網(wǎng)格或者說(shuō) GridView 小部件是Yii中最強(qiáng)大的部件之一。有興趣的可以了解一下。2017-01-01用Laravel Sms實(shí)現(xiàn)laravel短信驗(yàn)證碼的發(fā)送的實(shí)現(xiàn)
這篇文章主要介紹了用Laravel Sms實(shí)現(xiàn)laravel短信驗(yàn)證碼的發(fā)送的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11PHP explode()函數(shù)的幾個(gè)應(yīng)用和implode()函數(shù)有什么區(qū)別
這篇文章主要介紹了PHP explode()函數(shù)的幾個(gè)應(yīng)用和implode()函數(shù)有什么區(qū)別,需要的朋友可以參考下2015-11-11php微信公眾平臺(tái)開(kāi)發(fā)(三)訂閱事件處理
這篇文章主要介紹了php微信公眾平臺(tái)開(kāi)發(fā)中的訂閱事件處理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12PHP用正則匹配form表單中所有元素的類(lèi)型和屬性值實(shí)例代碼
這篇文章主要介紹了PHP用正則匹配form表單中所有元素的類(lèi)型和屬性值的方法,文中給出了完整的實(shí)例代碼,大家可以直接參考學(xué)習(xí),下面來(lái)一起看看吧。2017-02-02