>  기사  >  백엔드 개발  >  ThinkPHP 몰 공지 기능 개발 문제 분석_php 예시

ThinkPHP 몰 공지 기능 개발 문제 분석_php 예시

WBOY
WBOY원래의
2016-12-05 13:28:201542검색

이 글은 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 += "<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 프로그래밍에 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.