fastadmin接口输出图片 自动拼接网站URL

先自定义常量

复制代码
1.文件接口路径 修改核心文件  application\common\controller\Api.php
    /**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        $this->request = is_null($request) ? Request::instance() : $request;

        // 控制器初始化
        $this->_initialize();
       //<--代码位置 -->
        if (!defined('IMG_PRE')) {
            define("IMG_PRE", $this->request->domain());//定义获取域名常量
//            define("IMG_PRE", 'https://yunlingshidai.oss-cn-shanghai.aliyuncs.com');//也可以是云端域名
        }
        //<--代码位置 -->
        // 前置操作方法
        if ($this->beforeActionList) {
            foreach ($this->beforeActionList as $method => $options) {
                is_numeric($method) ?
                    $this->beforeAction($options) :
                    $this->beforeAction($method, $options);
            }
        }
    }

ffastadmin 接口输出图片

复制代码
    //修改器
    public function getImageAttr($value)
    {
        if(empty($value)){
            return '';
        }
        $domain=defined("IMG_PRE")?IMG_PRE:'';
        $preg = "/^http(s)?:\\/\\/.+/";
        if(preg_match($preg,$value))
        {
            $data=$value;
        }else{
            $data=$domain.$value;
        }
        return $data;
    }
相关推荐
XGeFei15 小时前
【Fastapi学习笔记(3)】——资源的层级关系、安全性-幂等性、Field、工厂函数
笔记·学习·fastapi
情绪总是阴雨天~20 小时前
智能语音分析Agent项目
python·自动化·fastapi·langgraph
li星野1 天前
FastAPI 参数详解:路径参数、查询参数与请求体 —— 从入门到实战
服务器·学习·fastapi
燐妤1 天前
现代 Python Web 框架:FastAPI实战指南
python·fastapi
SilentSamsara1 天前
命令行工具开发:Click/Typer + 打包为独立二进制
linux·服务器·开发语言·前端·python·青少年编程·fastapi
RSTJ_16251 天前
PYTHON+AI LLM DAY SIXTY-THREE
fastapi
眸生1 天前
基于NeteaseCloudMusicApi的音乐app 支持 DeepSeek 自然语言找歌、批量导入歌单、下载音乐转换成MP3,下载歌词
android·python·kotlin·android studio·音频·fastapi·android jetpack
abigale032 天前
LangChain 实践4 7-1 项目初始化 + 基础Model I/O
langchain·fastapi·uvicorn·提示词模板·输出解析器·model i/o
SilentSamsara2 天前
SQLAlchemy 2.x:异步 ORM 与数据库迁移 Alembic 完整指南
开发语言·数据库·python·sql·青少年编程·oracle·fastapi
BUG研究员_2 天前
Web应用-FastAPI
python·fastapi