🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 代码 注意:这里这个是 `public` ,而不是 `private` ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class MenuController extends Controller { /** * 导出后台菜单语言包 */ public function _exportAppMenuDefaultLang() { $menus = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select(); $langDir = config('DEFAULT_LANG'); $adminMenuLang = CMF_ROOT . "data/lang/" . $langDir . "/admin_menu.php"; if (!empty($adminMenuLang) && !file_exists_case($adminMenuLang)) { mkdir(dirname($adminMenuLang), 0777, true); } $lang = []; foreach ($menus as $menu) { $lang_key = strtoupper($menu['app'] . '_' . $menu['controller'] . '_' . $menu['action']); $lang[$lang_key] = $menu['name']; } $langStr = var_export($lang, true); $langStr = preg_replace("/\s+\d+\s=>\s(\n|\r)/", "\n", $langStr); if (!empty($adminMenuLang)) { file_put_contents($adminMenuLang, "<?php\nreturn $langStr;"); } } } ```