On this page
指定文章分类下的文章api
controller层:application\api\controller\v1\PostClass.php
php
use app\common\validate\TopicClassValidate;
...
// 获取指定分类下的文章
public function post()
{
// 验证分类id和分页数
(new TopicClassValidate())->goCheck();
$list=(new PostClassModel)->getPost();
return self::showResCode('获取成功',['list'=>$list]);
}
route层:route\route.php
php
// 不需要验证token
Route::group('api/:version/',function(){
...
// 获取指定文章分类下的文章
Route::get('postclass/:id/post/:page', 'api/v1.PostClass/post');
...
});
model层:application\common\model\PostClass.php
php
// 关联文章模型
public function post(){
return $this->hasMany('Post');
}
// 获取指定分类下的文章(分页)
public function getPost(){
// 获取所有参数
$param = request()->param();
return self::get($param['id'])->post()->with([
'user'=>function($query){
return $query->field('id,username,userpic');
},'images'=>function($query){
return $query->field('url');
},'share'])->page($param['page'],10)->select();
}