On this page
图片列表
控制器 app/controller/admin/ImageClass.php
php
public function images()
{
$param = $this->request->param();
$limit = intval(getValByKey('limit',$param,10));
$page = getValByKey('page',$param,1);
$model = $this->request->Model->images();
$totalCount = $model->count();
$order = getValByKey('order',$param,'desc');
$where = [];
$keyword = getValByKey('keyword',$param,false);
if($keyword){
$where[] = [
['name','like','%'.$keyword.'%']
];
}
$list = $model->page($param['page'],$limit)->where($where)->order('id',$order)->select();
return showSuccess([
'list'=>$list,
'totalCount'=>$totalCount
]);
}
模型 app/model/ImageClass.php
php
// 获取当前相册下的图片
public function images(){
return $this->hasMany('Image');
}
路由 router/admin.php
php
Route::get('imageclass/:id/image/:page$','admin.ImageClass/images');
验证器 app/validate/admin/ImageClass.php
php
protected $rule = [
'page' => 'require|integer|>:0',
'id'=>'require|integer|>:0|isExist:ImageClass',
];
protected $scene = [
...
'images'=>['id','page']
...
];