《PHP教程:thinkPHP商城公告功能開發問題分析》要點:
本文介紹了PHP教程:thinkPHP商城公告功能開發問題分析,希望對您有用。如果有疑問,可以聯系我們。
相關主題:thinkphp教程
PHP實例本文實例分析了thinkPHP商城公告功能開發問題.分享給大家供大家參考,具體如下:
PHP實例效果如下
PHP實例
PHP實例1.定在頭部
PHP實例
position: fixed;
z-index: 999;
top: 0;
opacity:1;
PHP實例2.ajax處理json數據
PHP實例
// 獲取商城公告
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;
}
PHP實例設置dataType:'json'之后,json數據就直接可以通過json.的方式處理了.
PHP實例3.最后加載,頁面更好看.
PHP實例
$(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 += "<li><strong>"+n.content+"</strong></li>"
});
$(".top-notice").show();
$('#notice ul').html(""+html);
$('#notice').unslider(); // 輪播
}
});
PHP實例4.獲取sql語句的thinkphp處理
PHP實例
// 獲取公告
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');
}
}
}
PHP實例
$where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;
PHP實例巧妙的處理了這種邏輯關系.
PHP實例更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎教程》及《PHP模板技術總結》.
PHP實例希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2531.html