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;
    }
相关推荐
一尘之中3 小时前
Ubuntu 22.04 上 FastAPI 的完整安装与问题解决指南
ubuntu·fastapi·ai写作
PieroPc9 小时前
用FastAPI 后端 和 Vue3 前端写一个博客系统 例
前端·vue·fastapi
小北方城市网10 小时前
Python FastAPI 异步性能优化实战:从 1000 QPS 到 1 万 QPS 的踩坑之路
大数据·python·性能优化·架构·fastapi·数据库架构
simon_skywalker10 小时前
FastAPI实战笔记(七)集成 NoSQL数据库
nosql·fastapi
一碗面42116 小时前
不用第三方 API!FastAPI + PaddleOCR 自建身份证 OCR 服务实战
ocr·fastapi
Psycho_MrZhang1 天前
Django/Flask/FastAPI简要对比分析
django·flask·fastapi
曲幽2 天前
FastAPI + SQLite:从基础CRUD到安全并发的实战指南
python·sqlite·fastapi·web·jwt·form·sqlalchemy·oauth2
Psycho_MrZhang2 天前
FastAPI 设计思想总结
fastapi
七夜zippoe2 天前
依赖注入:构建可测试的Python应用架构
开发语言·python·架构·fastapi·依赖注入·反转
山沐与山2 天前
【Python】深入理解Python Web框架:从Flask到FastAPI的并发之路
python·flask·fastapi