tp6实现幻灯片接口(查询接口)

2022-05-24 11:52:50 浏览数 (1)

sql:

代码语言:javascript复制
-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- 主机: localhost
-- 生成日期: 2022-05-23 17:25:06
-- 服务器版本: 5.7.26
-- PHP 版本: 7.3.4

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = " 00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- 数据库: `kkk`
--

-- --------------------------------------------------------

--
-- 表的结构 `swiper`
--

CREATE TABLE `swiper` (
  `id` int(10) UNSIGNED NOT NULL,
  `swiper_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `img_url` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `swiper_order` int(11) NOT NULL,
  `is_show` tinyint(4) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- 转存表中的数据 `swiper`
--

INSERT INTO `swiper` (`id`, `swiper_name`, `img_url`, `swiper_order`, `is_show`) VALUES
(3, '空调促销', '/storage/swiper/d3\99a0533e2e96aec0f0c489b5979858.jpg', 23, 1),
(5, '手机', '/storage/swiper/50\3b4d3cff4c75444ab8480048c14e95.jpg', 34, 1);

--
-- 转储表的索引
--

--
-- 表的索引 `swiper`
--
ALTER TABLE `swiper`
  ADD PRIMARY KEY (`id`);

--
-- 在导出的表使用AUTO_INCREMENT
--

--
-- 使用表AUTO_INCREMENT `swiper`
--
ALTER TABLE `swiper`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

粘贴复制下面这句话。到上面的app.php文件中

代码语言:javascript复制
<?php
//  ----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
//  ----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
//  ----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
//  ----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
//  ----------------------------------------------------------------------
use thinkfacadeRoute;



Route::get('index', 'Index/index');

Route::get('swipers', 'Swiper/getSwipers');

控制器:

代码语言:javascript复制
<?php
declare (strict_types = 1);

namespace appapicontroller;
use thinkfacadeDb;

class Swiper
{
    public function getSwipers(){
		$swipers = Db::name('swiper')->where('is_show',1)->select()->toArray();
		if($swipers){
			$data = ['code'=>200,'msg'=>'success','data'=>$swipers];
		}else{
			$data = ['code'=>440,'msg'=>'no swiper'];
		}
		
		return json($data);
	}
}

0 人点赞