// 列表
public function index()
{
// 分类
$cate_id = input('cate_id','');
$base = Db::name('base')
-> where('is_show',1)
-> where('base_category_id', $cate_id)
-> order('show_time desc,id desc')
-> paginate(16, false, ['query' => ['cate_id' => $cate_id, 'page' => request()->param('page')]]);
return view('index', compact('cate_id','base'));
}
// 详情
public function baseInfo()
{
$id = input('id','');
if (empty($id)) {
return $this->redirect(url('home/Base/index'));
}
$top = Db::name('about_top') -> order('create_time','desc') -> find();
Db::name('base') -> where('id',$id) -> setInc('view');
$base_info = Db::name('base') -> where('id', $id) -> find();
if (empty($base_info)) {
return $this->redirect(url('home/Base/index'));
}
$cate = Db::name('base_category') -> where('id', $base_info['base_category_id']) -> find();
// 下一条数据
$after = Db::name('base')
-> where('is_show','=',1)
-> where('id','>',$id)
-> order('show_time asc')
-> find();
// 上一条数据
$before = Db::name('base')
-> where('is_show','=',1)
-> where('id','<',$id)
-> order('show_time desc')
-> find();
// 推荐数据
$num = 10;
$count = Db::name('base') -> where('is_show','=',1) -> count();
$tuijian_like = Db::name('base') -> where('is_show','=',1) -> limit($count) -> select();
shuffle($tuijian_like); // 打乱数组
$tuijian_like = array_slice($tuijian_like,0, $num); // 抽取指定数据
return view('info', compact('top','base_info','after','before','tuijian_like','cate'));
}
分页列表功能和详情功能
相关推荐
-
生成图片
from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageFilterdef create_image_with_text(size, color, text, font_path, font_size, text_color, shadow_color, output_path): """ Create a new image of specified size and color with centered text that has a border and shadow. :param size: A tuple con
-
获取指定目录下的所有图片信息
1 获取指定目录下的所有图片信息// 获取指定目录下的所有图片信息 public function getImagesInfo($directory) { $images = []; // 创建递归目录迭代器 $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ); // 遍历目录中的每个文件 foreach (
-
Thinkphp各版本的PHP要求
ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3