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;
    }
相关推荐
勘察加熊人14 小时前
fastapi房产销售系统
数据库·lua·fastapi
Amd79418 小时前
FastAPI Cookie 和 Header 参数完全指南:从基础到高级实战 🚀
fastapi·web开发·cookie·header·数据校验·安全性·api设计
Amd7942 天前
FastAPI 表单参数与文件上传完全指南:从基础到高级实战 🚀
fastapi·web开发·文件上传·form·file·api设计·表单参数
Amd7944 天前
FastAPI 请求体参数与 Pydantic 模型完全指南:从基础到嵌套模型实战 🚀
restful·fastapi·数据校验·api设计·嵌套模型·pydantic模型·请求体参数
黄小耶@6 天前
如何快速创建Fastapi项目
linux·python·fastapi
如果皮卡会coding7 天前
HTTP/2 服务器端推送:FastAPI实现与前端集成指南
前端·http·fastapi
_.Switch7 天前
高效API开发:FastAPI中的缓存技术与性能优化
python·缓存·性能优化·负载均衡·fastapi
2501_906934678 天前
如何安全获取股票实时数据API并在服务器运行?
java·运维·服务器·python·c#·fastapi
桐桐桐10 天前
FastAPI 学习笔记
python·学习·fastapi
一个水货程序员12 天前
使用python接入腾讯云DeepSeek
python·腾讯云·fastapi