chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace addon\forum\controller;
|
||||
|
||||
use ywxapp\controller\FrontendBase;
|
||||
|
||||
/**
|
||||
* 论坛前台控制器基类
|
||||
* 继承 AddonFrontend(插件专用前台基类,提供 fetch 与会员 auth 注入)
|
||||
* 注意:框架 BaseController 未暴露 assign(),这里补充 assign() 代理,与 docs 保持一致。
|
||||
*/
|
||||
class ForumFrontend extends FrontendBase
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedVerify = ['*'];
|
||||
|
||||
/**
|
||||
* 初始化:调用父类,并保证布局所需的 user 变量始终存在(游客为空数组)
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->assign('member', $this->member() ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* assign 代理,返回 $this 便于链式
|
||||
*/
|
||||
protected function assign($name, $value = null)
|
||||
{
|
||||
$this->view->assign($name, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录会员(未登录返回 null)
|
||||
* @return \ywxapp\model\Member|null
|
||||
*/
|
||||
protected function member()
|
||||
{
|
||||
if ($this->auth && $this->auth->isLogin) {
|
||||
return $this->auth->info;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否已登录
|
||||
*/
|
||||
protected function requireLogin(): bool
|
||||
{
|
||||
return $this->auth && $this->auth->isLogin;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user