当前位置:Gxlcms > PHP教程 > phpmvc开发实例详解(1/3)_PHP教程

phpmvc开发实例详解(1/3)_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

include("core/ini.php");
initializer::initialize();
$router = loader::load("router");
dispatcher::dispatch($router);

这个文件就只有4句,我们现在一句句来分析。
include(”core/ini.php”);

我们来看core/ini.php

set_include_path(get_include_path() . path_separator . "core/main");
//set_include_path — sets the include_path configuration option
function __autoload($object){
require_once("{$object}.php");
}

这个文件首先设置了include_path,也就是我们如果要找包含的文件,告诉系统在这个目录下查找。其实我们定义__autoload()方法,这个方法是在php5增加的,就是当我们实例化一个函数的时候,如果本文件没有,就会自动去加载文件。官方的解释是:
接下来我们看下面一句
initializer::initialize();
这就话就是调用initializer类的一个静态函数initialize,因为我们在ini.php,设置了include_path,以及定义了__autoload,所以程序会自动在core/main目录查找initializer.php.
initializer.php文件如下:

class initializer
{
public static function initialize() {
set_include_path(get_include_path().path_separator . "core/main");
set_include_path(get_include_path().path_separator . "core/main/cache");
set_include_path(get_include_path().path_separator . "core/helpers");
set_include_path(get_include_path().path_separator . "core/libraries");
set_include_path(get_include_path().path_separator . "app/controllers");
set_include_path(get_include_path().path_separator."app/models");
set_include_path(get_include_path().path_separator."app/views");
//include_once("core/config/config.php");
}
}
?>

这个函数很简单,就只定义了一个静态函数,initialize函数,这个函数就是设置include_path,这样,以后如果包含文件,或者__autoload,就会去这些目录下查找。

ok,我们继续,看第三句

$router = loader::load(”router”);

1 2 3

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444798.htmlTechArticle?php教程 include(core/ini.php); initializer::initialize(); $router = loader::load(router); dispatcher::dispatch($router); 这个文件就只有4句,我们现在一句句来分析...

人气教程排行