<blockquote></blockquote>
这个文件就只有4句,我们现在一句句来分析。
include(”core/ini.php”);
我们来看core/ini.php
<blockquote><?php<br />set_include_path(get_include_path() . path_separator . "core/main");<br />//set_include_path — sets the include_path configuration option<br />function __autoload($object){<br />require_once("{$object}.php");<br />}</blockquote>这个文件首先设置了include_path,也就是我们如果要找包含的文件,告诉系统在这个目录下查找。其实我们定义__autoload()方法,这个方法是在php5增加的,就是当我们实例化一个函数的时候,如果本文件没有,就会自动去加载文件。官方的解释是:
接下来我们看下面一句
initializer::initialize();
这就话就是调用initializer类的一个静态函数initialize,因为我们在ini.php,设置了include_path,以及定义了__autoload,所以程序会自动在core/main目录查找initializer.php.
initializer.php文件如下:
<blockquote><?php<br />class initializer<br />{<br />public static function initialize() {<br />set_include_path(get_include_path().path_separator . "core/main");<br />set_include_path(get_include_path().path_separator . "core/main/cache");<br />set_include_path(get_include_path().path_separator . "core/helpers");<br />set_include_path(get_include_path().path_separator . "core/libraries");<br />set_include_path(get_include_path().path_separator . "app/controllers");<br />set_include_path(get_include_path().path_separator."app/models");<br />set_include_path(get_include_path().path_separator."app/views");<br />//include_once("core/config/config.php");<br />}<br />}<br />?><br /></blockquote>这个函数很简单,就只定义了一个静态函数,initialize函数,这个函数就是设置include_path,这样,以后如果包含文件,或者__autoload,就会去这些目录下查找。
ok,我们继续,看第三句
立即学习“PHP免费学习笔记(深入)”;
$router = loader::load(”router”);
1 2 3
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号