国产毛片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://www.qingdxww.cn/thread-121475-1-1.html     【打印本頁】

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

廠商推薦

  • Microchip視頻專區
  • 想要避免發生災難,就用MPLAB® SiC電源仿真器!
  • 無線充電基礎知識及應用培訓教程3
  • 了解一下Microchip強大的PIC18-Q24 MCU系列
  • 基于CEC1712實現的處理器SPI FLASH固件安全彈性方案培訓教程
  • 貿澤電子(Mouser)專區
關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 青青在线视频 | 亚洲一二三四 | 国产91精品一区二区 | 中文字幕精品一区二区日本 | 精品成人一区二区三区免费视频 | 精品国产三级a | 亚洲黄色高清视频 | 一级成人a做片免费 | 女人wwxxxxx| 99精品网 | 日韩中文字幕高清在线专区 | 欧美在线成人午夜影视 | 黄色免费在线视频 | 午夜在线视频网站 | 欧美高清在线精品一区二区不卡 | 九九久久国产精品 | 久久99精品麻豆国产 | 日日噜夜夜噜 | 99久在线| 日本精品久久久 | 六月婷婷色 | 国产玖玖玖精品视频 | 久热国产在线视频 | 亚洲欧美国产日本 | 国产色av| 羞羞视频网站 | 老外黑人一级毛片 | 免费一级欧美大片久久网 | 久青草香蕉精品视频在线 | 国产欧美日韩在线不卡第一页 | www.五月婷婷 | 亚洲国产精品久久久久久网站 | 国产国产人免费视频成69大陆 | 青青草原成人 | 亚洲影视在线观看 | 国产一区二区在线免费观看 | 一级毛片免费观看久 | 曰韩在线视频 | 永久黄色免费网站 | 美女网站免费福利视频 | 亚洲欧美日韩高清一区二区一 |