thinkPHP商城公告功能開發問題分析_php執行個體

來源:互聯網
上載者:User
本文執行個體分析了thinkPHP商城公告功能開發問題。分享給大家供大家參考,具體如下:

效果如下

1.定在頭部

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

2.ajax處理json資料

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

設定dataType:'json'之後,json資料就直接可以通過json.的方式處理了。

3.最後載入,頁面更好看。

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

    4.擷取sql語句的thinkphp處理

    // 擷取公告function ajaxGetNotice() {    if (IS_AJAX) {      $this->mid;      // 擷取有效,且結束時間大於目前時間的,或者日期等於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') ;

    巧妙的處理了這種邏輯關係。

    更多關於thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)架構進階教程》、《Zend FrameWork架構入門教程》、《smarty模板入門基礎教程》及《PHP模板技術總結》。

    希望本文所述對大家基於ThinkPHP架構的PHP程式設計有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.