濮阳杆衣贸易有限公司

主頁 > 知識庫 > Yii框架引入coreseek分頁功能示例

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

熱門標(biāo)簽:電梯外呼線路板維修視頻 安陽自動外呼系統(tǒng)價格是多少 銀川ai電話機(jī)器人 地圖標(biāo)注風(fēng)向標(biāo) 芒果電銷機(jī)器人 臨沂智能電銷機(jī)器人軟件 上海公司外呼系統(tǒng)線路 十堰ai電話機(jī)器人效果怎么樣 浙江外呼電話系統(tǒng)軟件

本文實例講述了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()
{
  //模擬數(shù)據(jù)
  $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()]);
  //每頁條數(shù)
  $pagination->setPageSize(3);
  //執(zhí)行分頁
  $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;
  //實例化模型
  $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()]);
  //每頁條數(shù)
  $pagination->setPageSize(3);
  //執(zhí)行分頁
  $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ā)布時間/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-topictopic_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; //臨時變量
  $('#all').click(function(){
    $('input[type="checkbox"]').prop('checked',temp);
    //取反
    temp=!temp;
  })
  //批刪
  $('#del').click(function(){
    var checkAll=$('input[type="checkbox"]'); //獲取全部的復(fù)選框
    var length=checkAll.length; //計算長度
    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(); //刷新頁面
        //節(jié)點刪除
        $.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)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

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

您可能感興趣的文章:
  • Yii框架分頁實現(xiàn)方法詳解
  • Yii框架結(jié)合sphinx,Ajax實現(xiàn)搜索分頁功能示例
  • YII框架中搜索分頁jQuery寫法詳解
  • yii框架搜索分頁modle寫法
  • yii框架使用分頁的方法分析
  • Yii分頁用法實例詳解
  • Yii使用CLinkPager分頁實例詳解
  • Yii2分頁的使用及其擴(kuò)展方法詳解
  • Yii列表定義與使用分頁方法小結(jié)(3種方法)
  • yii2分頁之實現(xiàn)跳轉(zhuǎn)到具體某頁的實例代碼
  • yii2實現(xiàn)分頁,帶搜索的分頁功能示例
  • Yii框架分頁技術(shù)實例分析

標(biāo)簽:遵義 常州 徐州 荊門 寧夏 遂寧 武威 吐魯番

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Yii框架引入coreseek分頁功能示例》,本文關(guān)鍵詞  Yii,框架,引入,coreseek,分頁,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Yii框架引入coreseek分頁功能示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于Yii框架引入coreseek分頁功能示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    洛扎县| 盐边县| 侯马市| 临潭县| 广德县| 阳朔县| 台前县| 富裕县| 黄浦区| 阿巴嘎旗| 祥云县| 安西县| 本溪| 桂平市| 牡丹江市| 芮城县| 灵石县| 鸡西市| 都昌县| 揭阳市| 启东市| 崇明县| 老河口市| 汝州市| 丰台区| 湖南省| 青浦区| 津南区| 栖霞市| 岳西县| 洛阳市| 克什克腾旗| 石渠县| 潼关县| 金门县| 嵊泗县| 雷山县| 团风县| 精河县| 通城县| 青铜峡市|