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;
    }
相关推荐
jingyucsdn6 天前
AsyncIOScheduler与BackgroundScheduler的线程模型对比
fastapi
jingyucsdn7 天前
FastAPI集成APsecheduler的BackgroundScheduler+mongodb(精简)
fastapi
几道之旅7 天前
前端antd,后端fastapi,解决文件上传
前端·fastapi
Hello_WOAIAI8 天前
python中使用高并发分布式队列库celery的那些坑
python·fastapi
ZHOU_WUYI9 天前
FastAPI在 Nginx 和 Docker 环境中的部署
nginx·docker·fastapi
王学政210 天前
FastAPI 中间件
fastapi
小迅先生12 天前
AI开发 | Web API框架选型-FastAPI
开发语言·python·fastapi
老大白菜14 天前
双均线量化交易策略指南
python·fastapi
Msshu12314 天前
消费类,小家电产品如何做Type-C PD快充快速充电
python·单片机·嵌入式硬件·物联网·beautifulsoup·fastapi·tornado
engchina15 天前
使用Python和FastAPI构建网站爬虫:Oncolo医疗文章抓取实战
爬虫·python·fastapi