Php MVC single-point tunnel port

Source: Internet
Author: User
Php MVC single point Portal Php MVC single point portal? /Index. php & lt ;? /*** MVC demo ** only implements the most basic MVC functions, excluding security processing, data filtering, and other optimization measures. */Define ('site _ path' mvc spof entry of Php

MVC single point of entry for Php

?

/Index. php

/**

* MVC demo

* Only implement the most basic MVC functions, excluding security processing, data filtering, and other optimization measures.

*/

Define ('site _ path', str_replace (", '/', dirname (_ FILE _); // define the system directory

$ Controller = (! Empty ($ _ GET ['controller'])? $ _ GET ['controller']: 'index'; // gets the controller. the default index

$ Action = (! Empty ($ _ GET ['action'])? $ _ GET ['action']: 'index'; // method name, default index

$ Controller_name = $ controller. 'controller ';

$ Controller_file = SITE_PATH. '/app/controller/'. $ controller_name. '. class. php'; // Obtain the controller file

If (file_exists ($ controller_file )){

Require_once ($ controller_file );

$ Controller = new $ controller_name ();

$ Controller-> {$ action. 'action '}();

} Else {

Die ('The corresponding controller cannot be found! ');

}

?>

?

Corresponding demo

/App/controller/testController. class. php (note the path)

/**

* MVC demo

* Only implement the most basic MVC functions, excluding security processing, data filtering, and other optimization measures.

*/

Class testController

{

Function testAction (){

Echo 'Hello, World! ';

}

}

?>

Open the browser and enter http: // path/to/yoursite/index. php? Controller = test & action = test (change your path accordingly). If you see Hello, World! The first step of MVC is that the single point of access is successful!

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.