Discuz!大师网

搜索
查看: 980|回复: 0

Discuz!开发之文件加载路径函数libfile()介绍

[复制链接]
发表于 2017-4-7 20:15:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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

函数介绍
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

回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-25 12:21 , Processed in 0.024100 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表