CI分析之调用机制(1)[加载了哪些类文件]
原文地址: http://www.mycode114.com/archives/138前言
其实我比较反感使用框架的。因为它为了大家实现各种项目个性化的使用,做了很多扩展性的设计。有很多二次开发的机制,同一个操作设计出不同的实现方案。
但如果整个项目都是自己在把握的话,这些机制就是没有必要的。但又不得不承认,它给开发带来了很多便利。 你可以少写很多的基础代码,自带的类库。也可以让你省不少事。
我觉得PHPCMS V9那种文件目录存放方式已经很好了。CI号称最小内核之一,呵呵。
那我扣出PHPCMS V9那个内核机制,可以不用之一了.,咳咳,又不谦虚了,低调,低调。
不过既然项目用CI,那我就好好学习学习。还是会吸收不少新的东西。 CI框架就如同它自己号称的一样,不是很大,看明白就行了,写出来也是重复的。但还是写出来吧, 向作者致敬,为CI社区作贡献。
水平有限,难免理解错误,怡笑大方--!
进入正题:
加载了哪些文件
前面不多说,CI都有注释。是定义文件目录路径的变量和常量。
最后一句:
require_once BASEPATH.'core/CodeIgniter.php';
通过上面的代码,加载了system/core/CodeIgniter.php
在CodeIgniter.php中加载了控制器
// Load the base controller class
require BASEPATH.'core/Controller.php';
控制器类Controller的构造函数加载了,公共要加载的类文件.
public function __construct()
{
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
$this->load =& load_class('Loader', 'core');
$this->load->initialize();
log_message('debug', "Controller Class Initialized");
}
foreach的上面的注释说得很清楚.注册的对象已经被框架入口文件以变量的方式实例化了,
所以CI能运行一个超级大对象.
至于怎么用$this对象, 对象是如何被注册的.不在本文分析之列.
我们只需要将is_loaded打印出来, 其实也就是那个$class变量
print_r(is_loaded());
exit;
看看里面有什么
Array
(
=> Benchmark
=> Hooks
=> Config
=> Utf8
=> URI
=> Router
=> Output
=> Security
=> Input
=> Lang
)
上面都是通过foreach循环加载的, core/loader.php是单独加载的,并且调用它的initialize()方法.
$this->load =& load_class('Loader', 'core');
load_class是CI的神经中枢, 它会按Codeigniter框架设计的加载类和函数的优先级去加载函数和类.
所以框架总共加载了以上11个类文件, 顺便说一名PHPCMS BASE默认加载3个类来控制路路由和调度,它的内核只有这三个类.
如果要想知道别人的代码,加载了哪些类和函数,就在system/core/Common.php的load_class方法里把$_classes打印出来.
它里面包含了你可以用的全部信息:
例如:
Array
(
=> CI_Benchmark Object
(
=> Array
(
=> 0.07851000 1326005591
=> 0.07853700 1326005591
=> 0.11439300 1326005591
=> 0.11451100 1326005591
)
)
=> CI_Config Object
(
=> Array
(
=> http://localhost/remap/
=> index.php
=> AUTO
=>
=> english
=> UTF-8
=>
=> dw_
=> a-z 0-9~%.:_\-
=> 1
=>
=> c
=> m
=> d
=> 0
=>
=> Y-m-d H:i:s
=>
=>
=> ci_session
=> 7200
=>
=>
=>
=> ci_sessions
=>
=> 1
=> 300
=>
=>
=> /
=>
=>
=>
=> csrf_test_name
=> csrf_cookie_name
=> 7200
=>
=> local
=>
=>
)
=> Array
(
)
=> Array
(
=> application/
)
)
=> CI_Hooks Object
(
=>
=> Array
(
)
=>
)
=> CI_Utf8 Object
(
)
=> CI_URI Object
(
=> Array
(
)
=>
=> Array
(
)
=> Array
(
=> home
=> index
)
=> CI_Config Object
(
=> Array
(
=> http://localhost/remap/
=> index.php
=> AUTO
=>
=> english
=> UTF-8
=>
=> dw_
=> a-z 0-9~%.:_\-
=> 1
=>
=> c
=> m
=> d
=> 0
=>
=> Y-m-d H:i:s
=>
=>
=> ci_session
=> 7200
=>
=>
=>
=> ci_sessions
=>
=> 1
=> 300
=>
=>
=> /
=>
=>
=>
=> csrf_test_name
=> csrf_cookie_name
=> 7200
=>
=> local
=>
=>
)
=> Array
(
)
=> Array
(
=> application/
)
)
)
=> CI_Router Object
(
=> CI_Config Object
(
=> Array
(
=> http://localhost/remap/
=> index.php
=> AUTO
=>
=> english
=> UTF-8
=>
=> dw_
=> a-z 0-9~%.:_\-
=> 1
=>
=> c
=> m
=> d
=> 0
=>
=> Y-m-d H:i:s
=>
=>
=> ci_session
=> 7200
=>
=>
=>
=> ci_sessions
=>
=> 1
=> 300
=>
=>
=> /
=>
=>
=>
=> csrf_test_name
=> csrf_cookie_name
=> 7200
=>
=> local
=>
=>
)
=> Array
(
)
=> Array
(
=> application/
)
)
=> Array
(
=> home
=>
)
=> Array
(
)
=> home
=> index
=>
=> home
=> CI_URI Object
(
=> Array
(
)
=>
=> Array
(
)
=> Array
(
=> home
=> index
)
=> CI_Config Object
(
=> Array
(
=> http://localhost/remap/
=> index.php
=> AUTO
=>
=> english
=> UTF-8
=>
=> dw_
=> a-z 0-9~%.:_\-
=> 1
=>
=> c
=> m
=> d
=> 0
=>
=> Y-m-d H:i:s
=>
=>
=> ci_session
=> 7200
=>
=>
=>
=> ci_sessions
=>
=> 1
=> 300
=>
=>
=> /
=>
=>
=>
=> csrf_test_name
=> csrf_cookie_name
=> 7200
=>
=> local
=>
=>
)
=> Array
(
)
=> Array
(
=> application/
)
)
)
)
=> CI_Output Object
(
=>
=> 0
=> Array
(
)
=> Array
(
=> application/mac-binhex40
=> application/mac-compactpro
=> Array
(
=> text/x-comma-separated-values
=> text/comma-separated-values
=> application/octet-stream
=> application/vnd.ms-excel
=> application/x-csv
=> text/x-csv
=> text/csv
=> application/csv
=> application/excel
=> application/vnd.msexcel
)
=> application/macbinary
=> application/octet-stream
=> application/octet-stream
=> application/octet-stream
=> Array
(
=> application/octet-stream
=> application/x-msdownload
)
=> application/octet-stream
=> application/x-photoshop
=> application/octet-stream
=> application/octet-stream
=> application/octet-stream
=> application/oda
=> Array
(
=> application/pdf
=> application/x-download
)
=> application/postscript
=> application/postscript
=> application/postscript
=> application/smil
=> application/smil
=> application/vnd.mif
=> Array
(
=> application/excel
=> application/vnd.ms-excel
=> application/msexcel
)
=> Array
(
=> application/powerpoint
=> application/vnd.ms-powerpoint
)
=> application/wbxml
=> application/wmlc
=> application/x-director
=> application/x-director
=> application/x-director
=> application/x-dvi
=> application/x-gtar
=> application/x-gzip
=> application/x-httpd-php
=> application/x-httpd-php
=> application/x-httpd-php
=> application/x-httpd-php
=> application/x-httpd-php-source
=> application/x-javascript
=> application/x-shockwave-flash
=> application/x-stuffit
=> application/x-tar
=> Array
(
=> application/x-tar
=> application/x-gzip-compressed
)
=> application/xhtml+xml
=> application/xhtml+xml
=> Array
(
=> application/x-zip
=> application/zip
=> application/x-zip-compressed
)
=> audio/midi
=> audio/midi
=> audio/mpeg
=> audio/mpeg
=> Array
(
=> audio/mpeg
=> audio/mpg
=> audio/mpeg3
=> audio/mp3
)
=> audio/x-aiff
=> audio/x-aiff
=> audio/x-aiff
=> audio/x-pn-realaudio
=> audio/x-pn-realaudio
=> audio/x-pn-realaudio-plugin
=> audio/x-realaudio
=> video/vnd.rn-realvideo
=> Array
(
=> audio/x-wav
=> audio/wave
=> audio/wav
)
=> Array
(
=> image/bmp
=> image/x-windows-bmp
)
=> image/gif
=> Array
(
=> image/jpeg
=> image/pjpeg
)
=> Array
(
=> image/jpeg
=> image/pjpeg
)
=> Array
(
=> image/jpeg
=> image/pjpeg
)
=> Array
(
=> image/png
=> image/x-png
)
=> image/tiff
=> image/tiff
=> text/css
=> text/html
=> text/html
=> text/html
=> text/plain
=> text/plain
=> Array
(
=> text/plain
=> text/x-log
)
=> text/richtext
=> text/rtf
=> text/xml
=> text/xml
=> video/mpeg
=> video/mpeg
=> video/mpeg
=> video/quicktime
=> video/quicktime
=> video/x-msvideo
=> video/x-sgi-movie
=> application/msword
=> application/vnd.openxmlformats-officedocument.wordprocessingml.document
=> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
=> Array
(
=> application/msword
=> application/octet-stream
)
=> application/excel
=> message/rfc822
=> Array
(
=> application/json
=> text/json
)
)
=>
=>
=> Array
(
)
=> 1
)
=> CI_Security Object
(
=>
=> d9da26364faee11de0e2e140a16ec27d
=> 7200
=> csrf_test_name
=> csrf_cookie_name
=> Array
(
=>
=>
[.parentNode] =>
[.innerHTML] =>
=>
[-moz-binding] =>
[] => -->
[ < ![CDATA[
[] =>
)
=> Array
(
=>
=>
=>
=>
)
)
=> CI_Input Object
(
=>
=>
=> 1
=> 1
=>
=>
=> Array
(
)
=> CI_Security Object
(
=>
=> d9da26364faee11de0e2e140a16ec27d
=> 7200
=> csrf_test_name
=> csrf_cookie_name
=> Array
(
=>
=>
[.parentNode] =>
[.innerHTML] =>
=>
[-moz-binding] =>
[] => -->
[ < ![CDATA[
[] =>
)
=> Array
(
=>
=>
=>
=>
)
)
=> CI_Utf8 Object
(
)
)
=> CI_Lang Object
(
=> Array
(
)
=> Array
(
)
)
=> CI_Loader Object
(
=> 1
=> Array
(
=> 1
)
=> Array
(
=> application/
=> D:/wamp/www/remap/system/
)
=> Array
(
=> application/
)
=> Array
(
=> application/
=> D:/wamp/www/remap/system/
)
=> Array
(
)
=> Array
(
)
=> Array
(
)
=> Array
(
)
=> Array
(
)
=> Array
(
)
=> Array
(
=> unit
=> agent
)
)
) 很给力哦,哇大大...
页:
[1]