在Yii中如何引入和使用coreseek分頁功能,方法是什么
Admin 2022-07-08 群英技術(shù)資訊 820 次瀏覽
很多朋友都對(duì)“在Yii中如何引入和使用coreseek分頁功能,方法是什么”的內(nèi)容比較感興趣,對(duì)此小編整理了相關(guān)的知識(shí)分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲,那么感興趣的朋友就繼續(xù)往下看吧!本文實(shí)例講述了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; //班級(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í)例化分頁類
$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;
//實(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í)例化分頁類
$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ā)布時(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ì)算長度
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é)點(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!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:[email protected]進(jìn)行舉報(bào),并提供相關(guān)證據(jù),查實(shí)之后,將立刻刪除涉嫌侵權(quán)內(nèi)容。
猜你喜歡
PHP echo的用法是什么,簡單的應(yīng)用是怎樣的?下文的講解詳細(xì),步驟過程清晰,對(duì)大家進(jìn)一步學(xué)習(xí)和理解有一定的幫助。有這方面學(xué)習(xí)需要的朋友就繼續(xù)往下看吧!
PHP項(xiàng)目中發(fā)送網(wǎng)絡(luò)請求的方法是什么?對(duì)于php發(fā)送網(wǎng)絡(luò)請求,我們最常用的請求就是curl,有時(shí)我們也會(huì)用到file_get_contents函數(shù)發(fā)送網(wǎng)絡(luò)請求,但file_get_contents只能完成一些間單的網(wǎng)絡(luò)請求,稍復(fù)雜的就無法完成,例如文件上傳,
今天在做與后臺(tái)交互的的過程中,發(fā)現(xiàn)php對(duì)于接收的POST有一個(gè)限制,超出1000個(gè)字段之后便無法接收,項(xiàng)目要求在不改變PHP配置的情況下通過前端方式解決,通過分析并且網(wǎng)上差一些大牛的資料終于找到了解決方案,下面進(jìn)行介紹:首先,由于post的數(shù)據(jù)太多會(huì)導(dǎo)致PHP無法接收,那么解決思路就是將form表單中要進(jìn)行提交的數(shù)據(jù)封裝為一個(gè)json字段提交到后臺(tái),為了其他表單也會(huì)出現(xiàn)這樣的問題,則將
在本文中我們給大家整理了關(guān)于php防止表單重復(fù)提交的知識(shí)點(diǎn),有需要的朋友們跟著學(xué)習(xí)參考下。
本欄目講解一個(gè)高性能、簡單、跨平臺(tái)的PHP7代碼加密擴(kuò)展,有需要的朋友可以看看,一起學(xué)習(xí)討論。
推薦內(nèi)容
成為群英會(huì)員,開啟智能安全云計(jì)算之旅
立即注冊關(guān)注或聯(lián)系群英網(wǎng)絡(luò)
7x24小時(shí)售前:400-678-4567
7x24小時(shí)售后:0668-2555666
24小時(shí)QQ客服
群英微信公眾號(hào)
CNNIC域名投訴舉報(bào)處理平臺(tái)
服務(wù)電話:010-58813000
服務(wù)郵箱:[email protected]
投訴與建議:0668-2555555
Copyright ? QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版權(quán)所有
增值電信經(jīng)營許可證 : B1.B2-20140078 ICP核準(zhǔn)(ICP備案)粵ICP備09006778號(hào) 域名注冊商資質(zhì) 粵 D3.1-20240008