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;
    }
相关推荐
大模型丫丫5 小时前
FastAPI 入门指南:从零开始构建高性能 Python API
开发语言·python·fastapi
卷无止境5 小时前
Python的contextlib与 FastAPI 中的上下文管理
后端·python·fastapi
卷无止境5 小时前
FastAPI Events 深度解析与工程实践
后端·python·fastapi
小月土星1 天前
构建 AI 应用的后端,最主流的选择就是 Python + FastAPI。
后端·fastapi
微学AI2 天前
我把 800 行报错日志压成一张排障卡:用蓝耘元生代做 FastAPI 日志根因分析
网络·oracle·fastapi
捧 花2 天前
FastAPI 基础语法:从一个完整接口理解 Web API 的设计
前端·python·fastapi·middleware
卷无止境2 天前
除了开发api,FastAPI其实也可以配合jinja2模板写页面
后端·python·fastapi
练习两年半的攻城狮2 天前
FastAPI + LlamaIndex Agent 流式对话踩坑实录
fastapi·llamaindex
卷无止境3 天前
Linux + Docker + FastAPI 工程化实践指南
后端·python·fastapi
皮卡丘不断更4 天前
手机优先的 Personal Ledger:把账目、学习和复盘放到同一个入口
数据库·sqlite·fastapi·开源项目·个人效率