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;
    }
相关推荐
小宁爱Python1 天前
FastAPI+Sqlite+HTML的登录注册与文件上传系统:完整实现指南
sqlite·html·fastapi
fairymt2 天前
LoRA 问答微调与部署全流程:基于 LLaMA-Factory + DeepSeek + FastAPI 打造专属大模型
fastapi
chenkangck5011 天前
Uvicorn 入门详解
python·fastapi
remandancy.h14 天前
FastAPI:(2)开启FastAPI
fastapi
里探15 天前
FastAPI的初步学习(Django用户过来的)
python·django·fastapi
从零开始学习人工智能15 天前
基于FastAPI与Selenium的智能开关状态管理系统实践
selenium·adb·fastapi
Python私教16 天前
FastAPI本地文档的定制技巧
fastapi
沛沛老爹18 天前
Celery+fastAPI/Flask实现高性能应用
python·flask·fastapi·celery·web框架集成
remandancy.h18 天前
FastAPI:(10)中间件与CORS
中间件·fastapi
浠寒AI19 天前
【FastAPI高级实战】结合查询参数与SQLModel Joins实现高效多表查询(分页、过滤、计数)
fastapi