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;
    }
相关推荐
忘忧记10 小时前
pythonQT版本的图书管理系统
python·fastapi
PieroPc14 小时前
生成 自己喜欢 Fastapi 写法的文件和目录 (应用放在fnosDocker 上)
fastapi
dreams_dream14 小时前
FastAPI
fastapi
SmartBrain17 小时前
FastAPI实战(第二部分):用户注册接口开发详解
数据库·人工智能·python·fastapi
ん贤18 小时前
Scrapy 嵌入 FastAPI 的坑:Asyncio/Twisted 桥接 + 代理池设计
python·scrapy·fastapi
PieroPc2 天前
使用 uvicorn + NSSM(作为 Windows 服务)
windows·fastapi·nssm·uvicorn
SmartBrain2 天前
FastAPI实战:基于 SQLAlchemy的后端接口开发流程
数据库·架构·fastapi
岱宗夫up2 天前
FastAPI进阶3:云原生架构与DevOps最佳实践
前端·python·云原生·架构·前端框架·fastapi·devops
PieroPc2 天前
在飞牛 NAS(fnOS)上使用 Docker 部署 FastAPI 应用(这个是从错误学习教程 图是可以的)
学习·docker·fastapi·飞牛nas
七夜zippoe2 天前
集成测试实战:构建可靠的测试金字塔体系
python·log4j·e2e·fastapi·持续集成·flask api