chaoyu/app/widget/Menu.php

28 lines
741 B
PHP
Raw Permalink Normal View History

<?php
namespace app\widget;
use think\facade\{View, Cache};
use app\model\Category;
class Menu
{
public function index($categoryId)
{
2020-11-25 10:48:29 +00:00
$menus = Cache::get('front_menus');
2020-11-25 12:15:51 +00:00
$menus = null;
if(empty($menus)){
$menus = Category::getListForFrontMenu();
2020-11-25 10:48:29 +00:00
Cache::set('front_menus', $menus, 3600 * 12);
}
$currentFirstId = 0;
if (is_numeric($categoryId) && $categoryId > 0) {
$currentFirstId = Category::firstGradeById($categoryId);
}
$data = [
'categoryId' => $categoryId,
'menus' => $menus,
2020-11-25 02:32:42 +00:00
'currentFirstId' => $currentFirstId,
];
return View::assign($data)->fetch('public/menu');
}
}