mineadmin / MineAdmin

🎉🎉🎉 MineAdmin是基于Hyperf框架 和 Vue3+Vite5 开发的前后端分离权限管理系统,自适应多终端。特色:后端 crud 生成 + 前端低代码 json 化配置

Home Page:https://www.mineadmin.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] 一个示例问题

zds-s opened this issue · comments

commented

Before you submit this issue, you has been search all existed issues and search the documentation

  • I've been search all existed issues
  • I've been read all documentation

Describe your question

请问在 MineAdmin 本仓库中怎么获取当前用户id。它的实现原理是怎么实现的。如果可以,请用中文1回复

在MineAdmin中获取当前用户ID,可以通过SystemUserService服务的getInfo()方法实现。这个方法主要通过user()->getId()来获取当前登录用户的ID。如果用户已登录,此方法会返回用户的ID;否则,会抛出异常提示无法获取用户信息。这里是关键的实现代码示例:

public function getInfo(): array
{
    if ($uid = user()->getId()) {
        return $this->getCacheInfo((int) $uid);
    }
    throw new MineException(t('system.unable_get_userinfo'), 500);
}

getInfo()方法进一步调用getCacheInfo(),传入用户ID以获取包含用户信息的数组。这种方式确保了能够有效且安全地获取当前用户的ID及其它信息。

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.