控制器中的banner.php,打断点测试的结果如下图,即使是数据库里面也是按banner_id为1,2,3,4排序的。

模型中的banner.php只指定表为banner_item

<?php
/**
* Created by PhpStorm.
* User: wt271
* Date: 2017/6/9
* Time: 21:00
*/
namespace app\api\controller\v1;
use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\BannerMissException;
class Banner
{
public function getBanner($id)
{
(new IDMustBePostiveInt())->goCheck();
$banner = BannerModel::find($id);
//$banner = BannerModel::getBannerByID($id);
if(!$banner){
throw new BannerMissExecption();
}
return $banner;
}
}<?php
/**
* Created by PhpStorm.
* User: wt271
* Date: 2017/6/10
* Time: 8:47
*/
namespace app\api\model;
use think\Db;
use think\Exception;
use think\Model;
class Banner extends Model
{
protected $table = 'banner_item';
public static function getBannerByID($id){
//TODO:根据Banner ID号 获取Banner信息
// $result = Db::table('banner_item')->where('banner_id','=',$id)
// ->find();
// return $result;
}
}