补充一下,我自己重新整合了一下用户扩展函数文件:\\extend\\function.php放入// 用户自定义函数文件,函数名必须以 diy_ 前缀开头,避免与官方函数冲突报错if (!function_exists(\‘get_dopdf_value\‘)) { /** /** * 查询当前文章的dopdf字段的值 * * @param int $aid 文章ID * @param string $tableType 表类型,可选值:article, download, media, product, images * @return mixed 返回dopdf字段的值或null */ function get_dopdf_value($aid = 0, $tableType = \‘article\‘, $value = "xxx") { // 定义表名映射关系 $tableMap = [\‘article\‘ => \‘article_content\‘, \‘download\‘ => \‘download_content\‘, \‘media\‘ => \‘media_content\‘, \‘product\‘ => \‘product_content\‘, \‘images\‘ => \‘images_content\‘]; // 检查tableType是否合法 if (!array_key_exists($tableType, $tableMap)) { throw new \\InvalidArgumentException("无效的表类型: {$tableType}"); } // 获取表名 $tableName = $tableMap[$tableType]; // 定义查询条件 $condition = [\‘a.aid\‘ => $aid]; // 查询当前文章的dopdf字段的值 $record = \\think\\Db::name($tableName)->alias(\‘a\‘)->where($condition)->value($value); return trim_extra_after_ext($record); }}function trim_extra_after_ext($url){ $extensions = [\‘pdf\‘, \‘rar\‘, \‘zip\‘, \‘doc\‘, \‘docx\‘, \‘xls\‘, \‘xlsx\‘]; $pattern = \‘/(\‘ . implode(\‘|\‘, array_map(function ($ext) { return preg_quote($ext, \‘/\‘); }, $extensions)) . \‘)(\\\\?.*)?$/i\‘; if (preg_match($pattern, $url, $matches)) { $ext = $matches[1]; return substr($url, 0, strpos(strtolower($url), $ext) + strlen($ext)); } return $url;}前端视图文件调用<?php echo get_dopdf_value($eyou[\‘field\‘][\‘aid\‘],$eyou[\‘field\‘][\‘table\‘],"instructions"); ?>参数说明:第一个参数为文章ID、第二个参数为模型表明、第三个参数为你在后台设置的自定义字段名称,我是用原生PHP语法写的可以自行转换为thinkphp语法