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;
    }
相关推荐
勘察加熊人9 小时前
vue+d3js+fastapi实现天气柱状图折线图饼图
前端·vue.js·fastapi
Amd7943 天前
FastAPI中的依赖注入与数据库事务管理
fastapi·依赖注入·sqlalchemy·事务管理·异步编程·sql注入防护·数据库会话管理
背太阳的牧羊人3 天前
app = Flask(__name__)和app = FastAPI()有什么区别和联系
python·flask·fastapi
Amd7944 天前
FastAPI依赖注入作用域与生命周期控制
fastapi·作用域·依赖注入·资源管理·请求级作用域·应用级作用域·生命周期控制
老大白菜4 天前
FastAPI-Cache2: 高效Python缓存库
python·缓存·fastapi
老大白菜5 天前
Python FastAPI + Celery + RabbitMQ 分布式图片水印处理系统
分布式·python·fastapi
Amd7946 天前
FastAPI依赖注入实践:工厂模式与实例复用的优化策略
单例模式·性能优化·fastapi·工厂模式·依赖注入·多租户系统·实例复用
郁大锤6 天前
Flask与 FastAPI 对比:哪个更适合你的 Web 开发?
前端·flask·fastapi
Amd7947 天前
FastAPI依赖注入:从基础概念到应用
fastapi·错误处理·代码示例·认证系统·依赖注入测试·依赖解析·路由处理
清风序来8 天前
一,<FastApi>什么是FastApi?及框架介绍
fastapi