最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

thinkPHP商城公告功能開發(fā)問題分析

 更新時(shí)間:2016年12月01日 11:10:45   作者:牛逼的霍嘯林  
這篇文章主要介紹了thinkPHP商城公告功能開發(fā)問題,結(jié)合實(shí)例形式分析了基于thinkPHP實(shí)現(xiàn)商城公告功能所涉及的ajax交互及數(shù)據(jù)庫操作相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例分析了thinkPHP商城公告功能開發(fā)問題。分享給大家供大家參考,具體如下:

效果如下

1.定在頭部

position: fixed;
z-index: 999;
top: 0;
opacity:1;

2.ajax處理json數(shù)據(jù)

// 獲取商城公告
function getNotice() { // 獲取公告函數(shù)
  var res;
  $.ajax({
    type: "POST",
    url: "{sh::U('Store/Mall/ajaxGetNotice',array('mid'=>$mid))}",
    dataType:'json', // 設(shè)為json之后,就能夠很好的處理獲取的json數(shù)據(jù),json.status
    async: false,
    success: function(json){
      res = json;
    }
  });
  return res;
}

設(shè)置dataType:'json'之后,json數(shù)據(jù)就直接可以通過json.的方式處理了。

3.最后加載,頁面更好看。

$(document).ready(function(e) { // 主函數(shù)
  // 獲取公告
  var action_name = "{sh::ACTION_NAME}"; // 頁面使用thinkphp常量
  var json = getNotice();
  if ( action_name == 'index' && json.status == 1) { // 首頁并且公告存在
    $(".top").css("margin-top", "70px"); // jquery設(shè)置css
    $(".main-sidebar").css("top" ,"70px");
    var html = '';
    $.each(json.info, function(i, n){ // n為文本內(nèi)容
      html += "<li><strong>"+n.content+"</strong></li>"
    });
    $(".top-notice").show();
    $('#notice ul').html(""+html);
    $('#notice').unslider(); // 輪播
  }
});

4.獲取sql語句的thinkphp處理

// 獲取公告
function ajaxGetNotice() {
    if (IS_AJAX) {
      $this->mid;
      // 獲取有效的,且結(jié)束時(shí)間大于當(dāng)前時(shí)間的,或者日期等于0的公告
      $mallNoticeModel = M('Mall_notice');
      $where['mall_id'] = $this->mid;
      $where['status'] = 1;
      $where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;
      //SELECT * from sh_mall_notice where mall_id = 9 and status = 1 and (endtime = 0 or endtime>1458354366);
      $notice = $mallNoticeModel->where($where)->order('sort desc')->select();
      if (!empty($notice)) {
        $this->ajaxReturn(array('status'=>'1','info'=>$notice,'msg'=>"獲取成功"),'JSON');
      } else {
        $this->ajaxReturn(array('status'=>'2','info'=>$notice,'msg'=>"公告不存在"),'JSON');
      }
    }
}

$where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;

巧妙的處理了這種邏輯關(guān)系。

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。

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

相關(guān)文章

最新評論

中江县| 靖宇县| 来宾市| 准格尔旗| 永福县| 黎平县| 中阳县| 青龙| 松阳县| 宁津县| 芮城县| 沧州市| 佛教| 陵川县| 泾源县| 囊谦县| 简阳市| 萝北县| 双流县| 东海县| 普格县| 昌图县| 信阳市| 禄丰县| 城步| 宜黄县| 贵南县| 乌拉特后旗| 咸丰县| 瑞丽市| 台南市| 望都县| 建平县| 克拉玛依市| 天柱县| 镇雄县| 吉木乃县| 齐河县| 连山| 武宁县| 大新县|