国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

php 自動加載類 設置包含目錄 隨便new也不出錯

發布時間:2013-9-28 18:13    發布者:reggae
關鍵詞: php
get_include_path — 獲取當前的 include_path 配置選項

string get_include_path ( void )

set_include_path — 設置 include_path 配置選項
string set_include_path ( string $new_include_path )

首先set_include_path這個函數呢,是在腳本里動態地對PHP.ini中include_path進行修改的。
而這個include_path呢,它可以針對下面的include和require的路徑范圍進行限定,或者說是預定義一下。
就好像:
如果我們沒有設置這個值,可能我們需要寫一些完全的路徑:

[php]
  1.    include("123/test1.php");
  2.    include("123/test2.php");
  3.    include("123/test3.php");
  4.    require("123/test4.php");
  5.    require("123/test5.php");
  6. ?>

  7.       
  8.           include("123/test1.php");
  9.           include("123/test2.php");
  10.           include("123/test3.php");
  11.           require("123/test4.php");
  12.           require("123/test5.php");
  13.        ?>
復制代碼

來引入很多外部文件,但是如果我們設置了set_include_path("123/"),我們就可以用下面這段代碼代替。
[php]
  1.    set_include_path("123/");
  2.    include("test1.php");
  3.    include("test2.php");
  4.    include("test3.php");
  5.    require("test4.php");
  6.    require("test5.php");
  7. ?>

  8.       
  9.           set_include_path("123/");
  10.           include("test1.php");
  11.           include("test2.php");
  12.           include("test3.php");
  13.           require("test4.php");
  14.           require("test5.php");
  15.        ?>    那么這個函數它不僅可以定義一個文件夾,我們可以定義很多文件夾。如下所示,我要寫一個初始化函數:
  16. [php]
  17.   function initialize()

  18. set_include_path(get_include_path().PATH_SEPARATOR . "core/");
  19. set_include_path(get_include_path().PATH_SEPARATOR . "app/");
  20. set_include_path(get_include_path().PATH_SEPARATOR . "admin/");
  21. set_include_path(get_include_path().PATH_SEPARATOR . "lib/");
  22. set_include_path(get_include_path().PATH_SEPARATOR . "include/");
  23. set_include_path(get_include_path().PATH_SEPARATOR."data/");
  24. set_include_path(get_include_path().PATH_SEPARATOR."cache/");

  25.        function initialize()
  26. {
  27.     set_include_path(get_include_path().PATH_SEPARATOR . "core/");
  28.     set_include_path(get_include_path().PATH_SEPARATOR . "app/");
  29.     set_include_path(get_include_path().PATH_SEPARATOR . "admin/");
  30.     set_include_path(get_include_path().PATH_SEPARATOR . "lib/");
  31.     set_include_path(get_include_path().PATH_SEPARATOR . "include/");
  32.     set_include_path(get_include_path().PATH_SEPARATOR."data/");
  33.     set_include_path(get_include_path().PATH_SEPARATOR."cache/");
  34. }   
復制代碼

這樣它的路徑就成了:




.;C:\php5\pear;core/;app/;admin/;lib/;include/;data/;cache/


下面呢來一個實例.

[php]
  1. $include_path=get_include_path();                         //原基目錄  
  2. $include_path.=PATH_SEPARATOR."include/" ;
  3. $include_path.=PATH_SEPARATOR."classs/";
  4. $include_path.=PATH_SEPARATOR."libs/";
  5. //echo $include_path;  
  6. //設置include包含文件所在的所有目錄   
  7. set_include_path($include_path);

  8. function __autoload($className)
  9. {
  10. //echo '類 '.$className;  
  11. include strtolower($className).".class.php";
  12. }
  13. $Smarty = new Smarty;
  14. ?>

  15. $include_path=get_include_path();                         //原基目錄
  16. $include_path.=PATH_SEPARATOR."include/" ;
  17. $include_path.=PATH_SEPARATOR."classs/";
  18. $include_path.=PATH_SEPARATOR."libs/";
  19. //echo $include_path;
  20. //設置include包含文件所在的所有目錄
  21. set_include_path($include_path);

  22. function __autoload($className)
  23. {
  24. //echo '類 '.$className;
  25. include strtolower($className).".class.php";
  26. }
  27. $Smarty = new Smarty;
  28. ?>
復制代碼

當指定了多個目錄為 include_path ,而所要求包含的文件在這幾個目錄都有相同名稱的文件存在時,php選擇使用設定 include_path 時排位居前的目錄下的文件。

這樣就可以 直接new拉!!

本文地址:http://m.qingdxww.cn/thread-121475-1-1.html     【打印本頁】

本站部分文章為轉載或網友發布,目的在于傳遞和分享信息,并不代表本網贊同其觀點和對其真實性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問題,我們將根據著作權人的要求,第一時間更正或刪除。
您需要登錄后才可以發表評論 登錄 | 立即注冊

廠商推薦

  • Microchip視頻專區
  • Dev Tool Bits——使用MPLAB® Discover瀏覽資源
  • Dev Tool Bits——使用條件軟件斷點宏來節省時間和空間
  • Dev Tool Bits——使用DVRT協議查看項目中的數據
  • Dev Tool Bits——使用MPLAB® Data Visualizer進行功率監視
  • 貿澤電子(Mouser)專區
關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产不卡毛片 | 欧美卡1卡2卡三卡网站入口 | 成人网视频在线观看免费 | 亚欧乱色视频网站大全 | 成人自拍网站 | 麻豆精品久久久 | 成人亚洲欧美 | 日本精品一区二区三本中文 | 国产日产韩产麻豆1区 | 国产91剧情 | 四虎永久在线精品国产馆v视影院 | 毛片激情| 国产va免费高清在线观看 | 欧美日韩精品一区二区另类 | 麻豆va在线精品免费播放 | 国产片在线看 | 六月婷婷网视频在线观看 | 99久久香蕉国产综合影院 | h在线观看免费 | 麻豆网站视频 | 一本色道久久88加勒比—综合 | 久久99这里只有精品国产 | 精品99一区二区三区麻豆 | 亚洲日本一区二区三区在线不卡 | 日本精品国产 | 一个色亚洲 | 国产精品1区2区3区 国产精品1区2区 | 天堂在线资源网 | 香蕉欧美 | 青青伊人国产 | 特级毛片8级毛片免费观看 特级黄a三级三级三级 | 亚洲成年网站在线观看 | 高清h黄动漫在线观看 | 新91免费| 欧美日韩精品一区二区免费看 | 一级毛片视屏 | 香蕉精品在线 | 成人网在线播放 | 欧美日韩在线免费 | 亚洲精品免播放器在线观看 | 亚瑟天堂久久一区二区影院 |