Discuz!开发之文件加载路径函数libfile()介绍 [复制链接]

moqu8 2018-5-1

6 0
定义位置:
source\function\function_core.php
函数代码
function libfile($libname, $folder = '') {  
    $libpath = '/source/'.$folder;  
    if(strstr($libname, '/')) {  
        list($pre, $name) = explode('/', $libname);  
        $path = "{$libpath}/{$pre}/{$pre}_{$name}";  
    } else {  
        $path = "{$libpath}/{$libname}";  
    }  
    return preg_match('/^[\w\d\/_]+$/i', $path) ? realpath(DISCUZ_ROOT.$path.'.php') : false;  
}  

函数介绍

libfile($libname, $folder = '')

包含2个参数:$libname 和 $folder

该函数读取source目录下的$folder子目录作为基础部分。

例如 require_once libfile('function','plugin/test/');

实际为 require_once /source/plugin/test/function.php

另外当$libname中包含/的时候,把$libname分为前后两部分,前面部分为子目录。

规则为:/source/$folder/$libname_pre/$libname_pre_$libname_end.php

实例一:

require_once libfile('function/cache');

实际为 require_once /source/function/function_cache.php

实例二:

require_once libfile('portal/view', 'module');

实际为:require_once /source/module/portal/portal_view.php



最新回复 (0)
返回
支持中心
邮箱:winkill2012@qqcom
新站优化中!部分功能尚未完善,敬请谅解!
支持中心