《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实例巧妙的处理了这种逻辑关系.
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, LeCMS, ClassCMS, Fastadmin, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。