chaoyu/app/widget/Menu.php

28 lines
741 B
PHP

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