-
- require 'command/config.php';
- require 'command/app.php';
- app::run($config);
- ?>
-
Copy code
Load the system configuration file, and then load the system configuration through the engine.
2. Engine
-
- public function run($config){
- header("Content-type:text/html;charset=utf-8");
- self::$config = $config ; //Load system configuration
- self::copyright();
- self::testsystem(); //System environment
- self::setsystem(); //Set system parameters
- self::incinfo();
- if( !IN_WEB){exit('The website is closed for maintenance, please visit later!');}
- defined('KEHENG_DEBUG') or define('KEHENG_DEBUG',true); // Whether to debug mode
- self::setpath( ); //Set the system path
- self::getdatabase(); //Test the database
- self::loadlib(); //Load the library
- self::getRouteConfig(); //Run the route and load the controller
- }
-
Copy the code First, set the configuration file, then test the system parameters, load the system module, obtain the website information file configured in, set the path required for the website, test the database parameters in the system configuration, load the library file, and finally It is to load the route to obtain the request address.
The above process is just a set I wrote based on my own learning, but it lacks cache. How should the cache be set up specifically?
The database test here is based on which type of database is configured, and then the encapsulation file for the operation of that type of database is loaded.
3. Routing
The following is the last function above, which loads the controller file and obtains the request method according to the configuration file.
- /**
- 路由
- @link http://bbs.it-home.org
- */
- public function getRouteConfig(){
- $route_type=self::$config[route][url_type];
- switch($route_type){
- case 1:
- //echo $_SERVER['SCRIPT_NAME'].'
';
- $query_string=$_SERVER['QUERY_STRING'];
- //echo $_SERVER['REQUEST_URI'].'< ;br />';
- $urlstr=$_GET['controller'];
- break;
- case 4:
- $url = end(explode('/', $_SERVER["PHP_SELF"]));
- $ urlstr = strtolower(substr($url,0,-4));
- break;
- }
- if(file_exists(Contr_DIR.'Controller.php')){
- require Contr_DIR.'Controller.php';
- //echo $urlstr;
- $template = self::$config['Templates'];
- controller::load($urlstr,$template);
- }else{
- exit('Controller file does not exist');
- }
- }
Copy code
4. Controller
The controller file is also quite simple. It just loads the model file and view file based on the address analyzed by the route.
-
-
- /**
- Controller
- @link http://bbs.it-home.org
- */
- class controller{
- public $obj;
- public function load($url,$template){
- $config=$template;
- if( file_exists(Model_DIR.$url.'.model.php')){
- $views = new views;
- //echo Model_DIR.$url.'.model.php';
- require Model_DIR.$url.'.model. php';
- $temp = $config[$url][0];
- if($temp!='' && $temp!=null && isset($temp)){
- if(file_exists(Templ_DIR.$temp) ){
- //echo Templ_DIR.$temp;
- require Templ_DIR.$temp;
- }else{
- exit('View file does not exist!'.$temp);
- }
- }else{
- exit('This page does not exist Set display template! '.$temp);
- }
- unset($views);
- }else{
- exit('Model file does not exist:'.$url.'.model.php');
- }
- }
- }
-
Copy code
Note:
All the data that needs to be output in the model file is output through a class such as views, including all system parameters in the view file in the package.
I don't know if this method is unnecessary. It turns out that I want to encapsulate all the data to be output.
Other template files are also encapsulated with classes.
As for how to write the cache in MVC, it is still a vague concept. When reading data, should the direction be to read the cache, then determine whether the cache exists, and then determine whether a cache needs to be established?
Looking forward to the guidance of experts, please join the official QQ group of Scripting School: 161228069 to participate in the discussion.
|