todo: 附件中文名的显示的一个例子

发布于 2024-11-13 19:23:10

附件中文名,非fa_attachment 即其他业务表的files字段,如果带出中文名,beforeWrite 查fa_attachmenth获取filename

首先业务表要增加一个字段reqattachment_name

self::beforeWrite,(function ($row) {


    //add by astonish 20220120
    //补充对reqattachment_name的填写 
    if(isset($row['reqattachment'])){
        //attachfiles是个字符串,用,号分隔成数组,每个去attachment表里查询一下 

            $attachfiles_names = array();
            $lines = explode(",", $row['reqattachment'] );    //,分开
        
        foreach ($lines as $attachfiles) {                    
                $result =  \think\Db::name('attachment')
                ->where('url', '=', $attachfiles)
                ->field("filename")
                ->find();
                
            $attachfiles_names[]= $result['filename'];
        } 

        $row["reqattachment_name"] = implode(',', $attachfiles_names);  
    }
    
});
0 条评论

发布
问题