• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    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-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"]'); //获取全部的复选框
        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!

    更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

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

    您可能感兴趣的文章:
    • Yii框架分页实现方法详解
    • Yii框架结合sphinx,Ajax实现搜索分页功能示例
    • YII框架中搜索分页jQuery写法详解
    • yii框架搜索分页modle写法
    • yii框架使用分页的方法分析
    • Yii分页用法实例详解
    • Yii使用CLinkPager分页实例详解
    • Yii2分页的使用及其扩展方法详解
    • Yii列表定义与使用分页方法小结(3种方法)
    • yii2分页之实现跳转到具体某页的实例代码
    • yii2实现分页,带搜索的分页功能示例
    • Yii框架分页技术实例分析
    上一篇:Yii2框架自定义验证规则操作示例
    下一篇:Yii2框架实现利用mpdf创建pdf文件功能示例
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    Yii框架引入coreseek分页功能示例 Yii,框架,引入,coreseek,分页,