chaoyu/app/widget/Menu.php

32 lines
880 B
PHP
Executable File

<?php
namespace app\widget;
use think\facade\{View, Cache};
use app\model\Category;
class Menu
{
public function index($categoryId, $lang = 'cn')
{
$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,
];
if ($lang == 'en') {
return View::assign($data)->fetch('en/public/menu');
} else {
return View::assign($data)->fetch('public/menu');
}
}
}