<?php/** * PHP Single File framework design * 1, MVC architecture Implementation * 2, URL routing principle */URL Routing principle/** * Routing action * Gets the C and a variables in the URL, executes the class C corresponding method A, implements different routes */ClassApp {Public $c;public $a;PublicfunctionRun() {$c =Isset ($_get[' C '])? $_get[' C ']:"Index";The URL provides a variable name for the class name $a =Isset ($_get[' A '])? $_get[' A ']:"Index";The URL provides a method name for the variable name $c. ="Controller";if (class_exists ($c) && method_exists ($c, $a)) {$o =New $c (); $o $a (); }else{Echo"Error";Exit (); } }}MVC architecture/** * Model Layer * GET Application Data effect */ClassModel {//Todo:link db, get data}/** * View class * compile, cache, and display templates */ClassView {PublicfunctionRender($TPL) {Echo"Hi,". $tpl;//TODO: Specific HTML template}}/** * Controller * All function controllers inherit the class */ClassController {Public $view;Public $model;Publicfunction__construct() {$this->view =New View ();$this->model =New Model (); }PublicfunctionDisplay($TPL ="") {Echo$this->view->render ($TPL);Exit (); }}Specific function development class indexcontroller extends Span class= "Hljs-title" >controller {/** * Website Home */public function index $this->display ( "Index");} /** * Website list */public function list () {$ This->display ( "List");}} //Single file entry $app = new app (); $app->run ();
PHP Single File entry framework analysis