微信小程序之輪播圖(PHP)

首先是wtmlajax

<swiper class="">//微信輪播圖組件swiper
    <block wx:for="{{img_urls}}" wx:key="*this"> //block是標籤
        <swiper-item>
            <image src="{{item.img}}" class=""></image>//輪播的圖片
        </swiper-item>
    </block>   
 </swiper >

而後是js,相似一個Ajax數據庫

wx.request({ // 獲取輪播圖
      url: url,
      data: {
        custom_server: url2,
      },
      success: function (res) {
        that.setData({
          img_urls: 
        });
      }
    })

後臺獲取輪播圖的方法微信

public function get_banner ($type = 2) {
        $where=array();
        $server=$_SERVER['SERVER_NAME'];
        $cate = I('cate');
        $where['type']=$type;
        if($server == ''){
            if($cate == $type){
                $where['orderid']  = array('between','220,240');
            }else{
                $where['orderid']  = array('not between','220,240');
            }
        }$img_list=M('img')->where($where)->order('orderid desc')->field('id,img,url,orderid')->select();
        if(!empty($img_list)){
            foreach($img_list as $k2=>$v2){
                $arr2=explode(',',$v2['url']);
                $info=$this->get_link($arr2['0'],$arr2['1'],$arr2['2']);
                $img_list[$k2]['path']=$info['src'];
                $img_list[$k2]['jump_type']=$info['jump_type'];
            }
        }else{
            $where['type']=1;
            $img_list=M('img')->where($where)->order('orderid desc')->field('id,img,url')->select();
        }

        $this->ajax_return('success', 1, $img_list);
        exit;
    }

輪播圖的數據庫表img中字段this

img中存放的是圖片的地址url

相關文章
相關標籤/搜索