资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
自己编写基于MVC的轻量级PHP框架做WEB开发已有一年,每次都写重复的东西, 因此,想自己写一下框架,以后开发方便.本人之前学习asp.NET两年,JSP半年,可是后来因为工作的原故换成PHP.其实很不喜欢PHP的语法.还有PHP的函数名,每回都忘记.还是喜欢C#和JAVA的语法,哈.不过PHP有PHP的优点,不像ASP.NET那样封装了大量的东西,PHP更简单,更自由吧.还有应该就是PHP的开源组合. 写这编文章主要是因为那些东西要写给别人看,顺便发表了.高手看了别笑,菜鸟自己注意辨别,别被我的错误观点误导.文章中的代码下载一.文件结构index.php 入口文件 class 类存放的文件夹 base.class.php 基类 error.class.php 错误处理类 parms.class.php 获取参数类 control.class.php 控制类 model.class.php 模型类 template smartTemplate 类存放文件夹 db adodb 类存放文件夹 includes 包含文件类defines.inc.php 定义各路径文件 frameword.inc.php 框架处理文件 router.inc.php 路由文件,跟据参数,跳转不同路径 models 模式存放路径 views 模版文件保存路径 controls 存放控制类的文件夹 config.php 配置文件 admin 后台二.简单类图三. 入口文件,index.phpGet(a);/参数的获取GET方法request-Post(a);/获取POST参数?四. 路径定义文件 defines.inc.php五. 框架文件路径 frameword.inc.phpflibrary(demo);/调用demo类的Get函数则为 demo-Get(参数);request=load-library(params);/不同的目录用不同的URL方式require_once( PATH_BASE.DS.includes.DS.router.inc.php );?六. 基类函数包含了常用的功能 base.class.phppath_root =PATH_ROOT;this-path_PATH_CLASS;this-path_control=PATH_BASE.DS.controls;/加载模型/load modelfunction model(name) include_once (this-path_model.DS.name.php);model=null;if(model=null)model=new name();return model;/output page/*paramater name file name*paramater data replace*/function view(name,data) Template=self:template(file);Template-output(data);unset(Template);/create database connectionfunction database()include_once (PATH_CLASS.DS.db.DS.adodb.inc.php);this-db = ADONewConnection();this-db-createdatabase = true;result = this-db-Connect(self:config(db_host) , self:config(db_user), self:config(db_password), self:config(db_database) );if(!result)die(Could not connect to the database.);elsethis-db-Execute(set names utf8);return this-db;/create template function template(file)include_once (PATH_CLASS.DS.template.DS.class.smarttemplate.php);Template = new Smarttemplate(file);Template-template_dir=PATH_BASE.self:config(template_dir);Template-cache_dir =PATH_BASE.self:config(cache_dir);return Template;/import class function library(className) if(empty(className)return null;exit();elserequire_once(PATH_CLASS.DS.className.class.php);return new className();/return config valuefunction config(parameter)require_once(PATH_CONFIG.DS.config.php);return CONFIG:Ini()-parameter;?七. 控制器父类control.class.phprequest=this-library(params);/output page/*paramater name file name*paramater data replace*/function view(name,data=) Template=this-template(name.html);Template-assign(site_root,this-config(site_root);Template-assign(data);Template-output();unset(Template);/load modelfunction model(name) include_once (PATH_BASE.DS.models.DS.name.php);if(this-model=null)this-model=new name();return this-model;?八. 模型父类 model.class.phprequest=this-library(params);/create database c
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号