国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

Yii框架引入coreseek分頁功能示例

2024-05-05 00:06:27
字體:
來源:轉載
供稿:網友

本文實例講述了Yii框架引入coreseek分頁功能。分享給大家供大家參考,具體如下:

把sphinxapi.php改為SphinxClient.php 類文件隨便放,你能找到就行,我放在advanced/frontend/web/SphinxClient.php,打開common/config/bootstrap.php

在里面添加

Yii::$classMap['SphinxClient']='@frontend/web/SphinxClient.php';

地址寫正確

在需要用得控制其中 use SphinxClient

controller控制器

/** * 話題搜索 * * @author YING * @param void * @return void */public function actionTopic(){  //模擬數據  $studId=2; //用戶id  $classId=2; //班級id  $title=""; //為空  //實例化模型  $studTopic=new StudTopic();  //查詢  $data=$studTopic->find()->select('*')->innerJoin('stud_user','stud_topic.stud_id=stud_user.stud_id')->where(['class_id'=>$classId]);  //實例化分頁類  $pagination=new Pagination(['totalCount' => $data->count()]);  //每頁條數  $pagination->setPageSize(3);  //執行分頁  $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');  //模擬數據  $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'];    }  }  //轉化為字符串  $tidStr=isset($tidArray) ? implode(',',$tidArray) : 0;  //實例化模型  $studTopic=new StudTopic();  //查詢  $data=$studTopic->find()->select('*')->innerJoin('stud_user','stud_topic.stud_id=stud_user.stud_id')->where("t_id in ($tidStr)");  //實例化分頁類  $pagination=new Pagination(['totalCount' => $data->count()]);  //每頁條數  $pagination->setPageSize(3);  //執行分頁  $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視圖

<?phpuse yii/widgets/ActiveForm;use yii/helpers/Html;use yii/helpers/Url;use yii/widgets/LinkPager;?><table class="table">  <tr>    <td>標題</td>    <td>作者</td>    <td>發布時間</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><?phpecho LinkPager::widget([  'pagination' => $pages,]);?><script src="./css/js/jquery.1.12.min.js"></script><script>  //全選/全不選   var temp=true; //臨時變量  $('#all').click(function(){    $('input[type="checkbox"]').prop('checked',temp);    //取反    temp=!temp;  })  //批刪  $('#del').click(function(){    var checkAll=$('input[type="checkbox"]'); //獲取全部的復選框    var length=checkAll.length; //計算長度    var arr=new Array(); //定義數組    var str=""; //定義字符串    //循環    $.each(checkAll,function(k,v){      //判斷是否選中      if(checkAll[k].checked){        arr.push(checkAll.eq(k).attr('tid'));      }    })    //轉化為字符串    str=arr.join(',');    //ajax    var url="index.php?r=student/delete-all"; //地址    $.get(url,{str:str},function(msg){      if(msg){        //window.location.reload(); //刷新頁面        //節點刪除        $.each(arr,function(k,v){          $('#tr_'+v).remove();        });      }    },'json');  });  //反選  $("#fan").click(function(){    var checkAll=$('input[type="checkbox"]'); //獲取復選    $.each(checkAll,function(k,v){      this.checked=!this.checked;    })  });</script>

搞定 收工 ok!

希望本文所述對大家基于Yii框架的PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 永丰县| 临邑县| 塔河县| 方山县| 剑川县| 白水县| 神池县| 高碑店市| 新疆| 高碑店市| 鹤壁市| 辽源市| 嫩江县| 琼结县| 西昌市| 进贤县| 邹平县| 建德市| 阳春市| 玛沁县| 聊城市| 临汾市| 夏邑县| 巫溪县| 西和县| 澎湖县| 宁乡县| 鹤庆县| 哈尔滨市| 大田县| 杭州市| 涞源县| 通化市| 香港 | 永州市| 乐安县| 保亭| 溆浦县| 定州市| 赫章县| 涞水县|