Home >Backend Development >PHP Tutorial >Detailed explanation of php mvc development examples (1/3)_PHP tutorial
<blockquote><?php教程<br />include("core/ini.php");<br />initializer::initialize();<br />$router = loader::load("router");<br />dispatcher::dispatch($router);</blockquote>
This document only has 4 sentences. Let’s analyze each sentence now.
include("core/ini.php");
Let's look at 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>
This file first sets include_path, that is, if we want to find Included file tells the system to search in this directory. In fact, we define the __autoload() method. This method was added in php5. When we instantiate a function, if the file does not exist, the file will be automatically loaded. The official explanation is:
Next, let’s look at the following sentence
initializer::initialize();
This means calling initialize, a static function of the initializer class, because we set include_path in ini.php , and __autoload is defined, so the program will automatically search for initializer.php in the core/main directory.
initializer.php file is as follows:
<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>
This function is very simple, it only defines a static Function, initialize function, this function is to set include_path, so that if files or __autoload are included in the future, they will be searched in these directories.
ok, let’s continue and look at the third sentence
$router = loader::load(”router”);
1 2 3