一个完整的MVC框架应该包括:M:基本数据处理功能,V:视图处理模块(模板引擎),C:控制器模块,异常处理,日志系统等等。每一个模块都需要精心设计。

今天自己写一个MVC框架,当然只是实现MVC原理的一个简单实现。

 

项目目录结构:

mymvc

--models

----news.php

----view.php

--controllers

----news.php

----router.php

--views

----news.php

index.php

设计我们的URL访问路径的结构:http://127.0.0.1/mymvc/index.php?news&article=mvc

一般框架设计采用单入口模式:即所有请求均由index.php文件来接受。

index.php的代码:

<?php
//应用的根目录就是index.php的父目录   
define("SERVER_ROOT", 'D:/wamp/www/mymvc');  

//你的域名.comm 是你的服务器域名  
define('SITE_ROOT' , '127.0.0.1/mymvc'); 

require_once(SERVER_ROOT . '/controllers/' . 'router.php');  

?>
View Code

相关文章: