TP5中模板内容的替换和全局配置

  1. 首先在application的配置文件config.php中添加:

    // 基础替换字符串
    use think\Request;
    
    $request = Request::instance();
    $base    = $request->root();
    $root    = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
    if ('' != $root) {
       $root = '/' . ltrim($root, '/');
    }
  2. 配置视图输出字符串内容的替换

       // 视图输出字符串内容替换
       'view_replace_str' => [
           '__EASYUI__' => $root.'/plugins/easyui',
           '__MUI__' => $root.'/plugins/mui',
           '__ADMINCSS__' => $root.'/admin/css',
           '__ADMINJS__' => $root.'/admin/js',
           '__INDEXCSS__' => $root.'/index/css',
           '__INDEXJS__' => $root.'/index/js',
           '__INDEXIMG__' => $root.'/index/img',
    
           /**定义图片路径**/
           '__Uploads__' => 'http://127.0.0.1/HaiFang360_2/uploads',
    

你可能感兴趣的:(PHP)