coreseek php 分页,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视图

use yii\widgets\ActiveForm;

use yii\helpers\Html;

use yii\helpers\Url;

use yii\widgets\LinkPager;

?>

标题作者发布时间操作

<?php foreach($topicInfo as $key => $val): ?>

= $val['t_title']?>= $val['stud_name']?>= date('Y-m-d H:i:s',$val['add_time'])?> 编辑|| 删除 删除

echo LinkPager::widget([

'pagination' => $pages,

]);

?>

//全选/全不选

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;

})

});

搞定 收工 ok!

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值