欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Yii實(shí)現(xiàn)文章列表置頂功能示例

 更新時(shí)間:2016年10月18日 11:38:20   作者:Love滿天星  
這篇文章主要介紹了Yii實(shí)現(xiàn)文章列表置頂功能,分析了文章置頂功能的實(shí)現(xiàn)步驟及相關(guān)代碼操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Yii實(shí)現(xiàn)文章列表置頂功能的方法。分享給大家供大家參考,具體如下:

我的理解:首先點(diǎn)擊獲取當(dāng)前ID,model層查詢所有sort字段,遍歷數(shù)據(jù),得到最大值,修改數(shù)據(jù),替換數(shù)據(jù),即可。

效果圖:

模型層:

//顯示列表
public function lists1()
{
    $arr=Yii::$app->db->createCommand("select * from acticle join type on type.t_id=acticle.t_id order by sort desc")->queryall();
    return $arr;
}
//置頂
public function top(){
    $arr=$this::find()->select("sort")->asArray()->all();
    //print_r($arr);die;
    $rows=array();
    foreach($arr as $key=>$v)
    {
      $rows[]=$v['sort'];
    }
    $max=array_search(max($rows),$rows);
    return intval($rows[$max]+1);
  }
  //修改數(shù)據(jù)
  public function update1($sort,$acticle_id){
    $arr=Yii::$app->db->createCommand()->update("acticle",['sort'=>$sort],['acticle_id'=>$acticle_id]);
    if($arr->execute()){
      return 1;
    }else{
      return 2;
    }
}

控制器:

//文章置頂
public function actionTopq(){
    $acticle_id=$_GET['id'];
    //echo $acticle_id;die;
    //獲取最大sort
    $model=new Acticle();
    $sort=$model->top();
    //修改數(shù)據(jù)
    $row=$model->update1($sort,$acticle_id);
    //echo $row;die;
    if($row==1){
      //替換數(shù)據(jù),置頂
      $res1=$model->lists1();
      $art=new Articles();
      $res6=$art->get_right($res1,5);
      return $res6;
    }else{
    return false;
    }
}

視圖層:

<!-- 文章列表 -->
<div class="r_230_b ma_b8" style="float:right;right:0;line">
<div class="news_t" ><h2><font color="#d52c99">最新動(dòng)態(tài)</font></h2></div>
<?php echo $res6;?>
</div>
<script>
function topq(ts){
  $.get("index.php?r=index/topq",{id:ts},function(msg){
    $('#sort').html(msg);
    //alert(msg);
  })
}
</script>

更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論