A brief analysis of PHP single file entry framework

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.