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;
    }
相关推荐
Sun_Sherry1 天前
FastAPI: websocket的用法及举例
websocket·网络协议·fastapi
无敌开心2 天前
fastAPI教程:进阶操作
计算机视觉·fastapi
写bug如流水8 天前
【FastAPI】使用 SQLAlchemy 和 FastAPI 实现 PostgreSQL 中的 JSON 数据 CRUD 操作
postgresql·json·fastapi
竹笋常青9 天前
《The Graceful Dance of Fog》
fastapi
Joker-Tong9 天前
使用fastapi搭建ChatGPT对话后台
chatgpt·fastapi
黑金IT9 天前
FastAPI 的隐藏宝石:自动生成 TypeScript 客户端
javascript·typescript·fastapi
longersking12 天前
FastAPI挂载静态资源
python·fastapi
写bug如流水12 天前
【FasAPI】使用FastAPI来实现一个基于RBAC(基于角色的访问控制)的用户权限控制系统
jvm·oracle·fastapi
指弹代码摄影狗13 天前
【Fastapi】参数获取,json和query
python·fastapi
用户6735598856115 天前
数据驱动,实时监控显威力 —— 淘宝商品详情API助力商家精准营销
后端·api·fastapi