<转>thinkphp——关于import中@表示的路径

thinkphp 

import  默认路径是系统的库目录thinkphp/lib,@表示项目库目录app/lib

convention.php

'DEFAULT_APP'           => '@',     // 默认项目名称,@表示当前项目


functions.php

    1. function import($class, $baseUrl = '', $ext='.class.php') {  
    2.     static $_file = array();  
    3.     static $_class = array();  
    4.     $class = str_replace(array('.', '#'), array('/', '.'), $class);  //用“/”替换“.”,用“.”替换“#”  
    5.     if ('' === $baseUrl && false === strpos($class, '/')) {  
    6.         // 检查别名导入  
    7.         return alias_import($class);  
    8.     }    //echo('<br>'.$class.$baseUrl);  
    9.     if (isset($_file[$class . $baseUrl]))  
    10.         return true;  
    11.     else  
    12.         $_file[$class . $baseUrl] = true;  
    13.     $class_strut = explode("/", $class);  
    14.     if (empty($baseUrl)) {  
    15.         if ('@' == $class_strut[0] || APP_NAME == $class_strut[0]) {  
    16.             //加载当前项目应用类库  
    17.             $baseUrl = dirname(LIB_PATH);    //LIB_PATH当前项目类库,如果当前项目名为App则LIB_PATH为“./App/Lib”  
    18.             $class = substr_replace($class, 'Lib/', 0, strlen($class_strut[0]) + 1);  
    19.         } elseif (in_array(strtolower($class_strut[0]), array('think', 'org', 'com'))) {  
    20.             //加载ThinkPHP基类库或者公共类库  
    21.             // think 官方基类库 org 第三方公共类库 com 企业公共类库  
    22.             $baseUrl = THINK_PATH . '/Lib/';  
    23.         } else {  
    24.             // 加载其他项目应用类库  
    25.             $class = substr_replace($class, '', 0, strlen($class_strut[0]) + 1);  
    26.             $baseUrl = APP_PATH . '/../' . $class_strut[0] . '/' . LIB_DIR . '/';  
    27.         }  
    28.     }  
    29.     if (substr($baseUrl, -1) != "/")  
    30.         $baseUrl .= "/";  
    31.     $classfile = $baseUrl . $class . $ext;  
    32.     if ($ext == '.class.php' && is_file($classfile)) {  
    33.         // 冲突检测  
    34.         $class = basename($classfile, $ext);  
    35.         if (isset($_class[$class]))  
    36.             throw_exception(L('_CLASS_CONFLICT_') . ':' . $_class[$class] . ' ' . $classfile);  
    37.         $_class[$class] = $classfile;  
    38.     }  
    39.     //导入目录下的指定类库文件  
    40.     return require_cache($classfile);  

posted on 2015-11-22 19:06  hahahahahai12  阅读(151)  评论(0)    收藏  举报

导航