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视图
标题 | 作者 | 发布时间 | 操作 | |
= $val['t_title']?> | = $val['stud_name']?> | = date('Y-m-d H:i:s',$val['add_time'])?> | 编辑||删除 | 删除 |