thinkPHP商城公告功能開發(fā)問題分析
本文實例分析了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', // 設為json之后,就能夠很好的處理獲取的json數(shù)據(jù),json.status async: false, success: function(json){ res = json; } }); return res; }
設置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設置css $(".main-sidebar").css("top" ,"70px"); var html = ''; $.each(json.info, function(i, n){ // n為文本內容 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; // 獲取有效的,且結束時間大于當前時間的,或者日期等于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程序設計有所幫助。
- php+mysql+jquery實現(xiàn)日歷簽到功能
- ThinkPHP+jquery實現(xiàn)“加載更多”功能代碼
- Thinkphp整合微信支付功能
- thinkphp實現(xiàn)分頁顯示功能
- thinkPHP統(tǒng)計排行與分頁顯示功能示例
- thinkPHP交易詳情查詢功能詳解
- thinkPHP訂單數(shù)字提醒功能的實現(xiàn)方法
- Thinkphp實現(xiàn)短信驗證注冊功能
- thinkphp框架實現(xiàn)數(shù)據(jù)添加和顯示功能
- ThinkPHP3.2.2實現(xiàn)持久登錄(記住我)功能的方法
- thinkPHP實現(xiàn)MemCache分布式緩存功能
- thinkphp實現(xiàn)圖片上傳功能
- thinkPHP實現(xiàn)簽到功能的方法
相關文章
PHP實現(xiàn)采集中國天氣網(wǎng)未來7天天氣
這篇文章主要介紹了PHP實現(xiàn)采集中國天氣網(wǎng)未來7天天氣方法,本文詳細的講解了需求的實現(xiàn),也可以做為學習PHP采集的入門教程,需要的朋友可以參考下2014-10-10