// +---------------------------------------------------------------------- declare (strict_types = 1); namespace addon\docs\controller; use addon\docs\model\DocsProject; use ywxapp\controller\FrontendBase; /** * 文档中心前台基类 * * 统一注入站点标题与项目列表,供顶部导航与项目切换使用。 * * @author ywxapp */ class DocsFrontend extends FrontendBase { // 文档为公开内容,不做登录拦截 protected $noNeedLogin = ['*']; protected $noNeedVerify = ['*']; /** * 插件配置 * @var array */ protected $docsConfig = []; /** * 初始化 */ public function _initialize() { parent::_initialize(); $this->docsConfig = $this->loadConfig(); $this->view->assign([ 'docsTitle' => $this->docsConfig['site_title'] ?? 'YwxApp 文档中心', 'projectList' => DocsProject::enabledList(), 'currentYear' => date('Y'), ]); } /** * 模板变量赋值 * * AddonFrontend 基类只暴露 $this->view,这里补一个代理方法, * 使前台控制器与后台 AddonBackend 保持一致的 assign() 写法。 * * @param string|array $name 变量名或键值数组 * @param mixed $value 变量值 * @return $this */ public function assign($name, $value = null) { $this->view->assign($name, $value); return $this; } /** * 读取插件配置 * * @return array */ protected function loadConfig(): array { try { $config = get_addon_config('docs'); return is_array($config) ? $config : []; } catch (\Throwable $e) { return []; } } }