chaoyu/app/widget/Menu.php

32 lines
880 B
PHP
Raw Normal View History

2022-09-16 03:44:40 +00:00
<?php
namespace app\widget;
use think\facade\{View, Cache};
use app\model\Category;
class Menu
{
2024-11-19 03:05:18 +00:00
public function index($categoryId, $lang = 'cn')
2022-09-16 03:44:40 +00:00
{
$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,
];
2024-11-19 03:05:18 +00:00
if ($lang == 'en') {
return View::assign($data)->fetch('en/public/menu');
} else {
return View::assign($data)->fetch('public/menu');
}
2022-09-16 03:44:40 +00:00
}
}