一、创建控制器
<?php
namespace app\common\taglib;
use think\auth\Auth;
use think\template\TagLib;
class MyTag extends TagLib
{
protected $tags = [
'auth' => ['attr' => 'rule', 'close' => 1]
];
/**
* 权限判断标签
* @param $tag
* @param $content
* @return string
*/
public function tagAuth($tag, $content)
{
$rule = $tag['rule'];
$auth = new Auth();
$uid = session('uid');
$res = $auth->check($rule, $uid);
$parseStr = '<?php if(' . intval($res) . '): ?>' . $content .'<?php endif; ?>';
return $parseStr;
}
}
二、配置
三、使用
{MyTag:auth rule='Group/index'}
<a href="{:url('Group/index')}">用户组</a>
{/MyTag:auth}