在Yii中如何引入和使用coreseek分页功能,方法是什么
Admin 2022-07-08 群英技术资讯 692 次浏览
很多朋友都对“在Yii中如何引入和使用coreseek分页功能,方法是什么”的内容比较感兴趣,对此小编整理了相关的知识分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获,那么感兴趣的朋友就继续往下看吧!本文实例讲述了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视图
<?php
use 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>
<?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"]'); //获取全部的复选框
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!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
swoole和socket的区别:socket是系统提供的对tcp/ip操作的接口,swoole这是对socket在进行一个封装并提供php操作接口的php扩展。
php7安装mongodb扩展的方法:首先下载“mongodb-1.6.0.tgz”;然后进入“mongodb-1.6.0”;最后修改php.ini,并重启即可。
PHP中的运算符分为:算术运算符、递增/递减运算符、比较运算符、逻辑运算符、数组运算符、三元运算符等。本章节我们将讨论 PHP 中不同运算符的应用。
今天小编就为大家分享一篇解决tp5在nginx下修改配置访问的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
dirname函数怎么使用?在PHP中,dirname()函数的作用是返回路径中的目录名称,那么具体dirname()函数的用法是什么呢?为让大家更好的理解dirname及原理,下面给大家分享一下实例。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008