Home > Backend Development > PHP Tutorial > Php的MVC单点通道口

Php的MVC单点通道口

WBOY
Release: 2016-06-13 10:31:09
Original
824 people have browsed it

Php的MVC单点入口

PhpMVC单点入口

?

/index.php

/**

* MVC演示demo

* 仅仅实现最基本的MVC功能,不包含安全处理,数据过滤,及其他优化措施。

*/

define(SITE_PATH,str_replace(,/',dirname(__FILE__)));//定义系统目录

$controller=(!empty($_GET['controller']))?$_GET['controller']:index;//获取控制器,默认index

$action=(!empty($_GET['action']))?$_GET['action']:index;//方法名称,默认index

$controller_name=$controller.’Controller’;

$controller_file=SITE_PATH./app/controller/.$controller_name..class.php;//获取控制器文件

if(file_exists($controller_file)){

require_once($controller_file);

$controller=new $controller_name();

$controller->{$action.’Action’}();

}else{

die(‘找不到对应的控制器!’);

}

?>

?

对应的一个演示demo

/app/controller/testController.class.php(注意路径)

/**

* MVC演示demo

* 仅仅实现最基本的MVC功能,不包含安全处理,数据过滤,及其他优化措施。

*/

class testController

{

function testAction(){

echo ‘Hello,World!’;

}

}

?>

打开浏览器,输入http://path/to/yoursite/index.php?controller=test&action=test(注意相应的修改你的路径),如果你看到Hello,World!说明MVC第一步,单点入口成功了!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template