自己编写基于MVC的轻量级PHP框架.doc

上传人:壹****1 文档编号:549208771 上传时间:2023-07-30 格式:DOC 页数:11 大小:46KB
返回 下载 相关 举报
自己编写基于MVC的轻量级PHP框架.doc_第1页
第1页 / 共11页
自己编写基于MVC的轻量级PHP框架.doc_第2页
第2页 / 共11页
自己编写基于MVC的轻量级PHP框架.doc_第3页
第3页 / 共11页
自己编写基于MVC的轻量级PHP框架.doc_第4页
第4页 / 共11页
自己编写基于MVC的轻量级PHP框架.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《自己编写基于MVC的轻量级PHP框架.doc》由会员分享,可在线阅读,更多相关《自己编写基于MVC的轻量级PHP框架.doc(11页珍藏版)》请在金锄头文库上搜索。

1、自己编写基于MVC的轻量级PHP框架做WEB开发已有一年,每次都写重复的东西, 因此,想自己写一下框架,以后开发方便.本人之前学习asp.NET两年,JSP半年,可是后来因为工作的原故换成PHP.其实很不喜欢PHP的语法.还有PHP的函数名,每回都忘记.还是喜欢C#和JAVA的语法,哈.不过PHP有PHP的优点,不像ASP.NET那样封装了大量的东西,PHP更简单,更自由吧.还有应该就是PHP的开源组合. 写这编文章主要是因为那些东西要写给别人看,顺便发表了.高手看了别笑,菜鸟自己注意辨别,别被我的错误观点误导.文章中的代码下载一.文件结构index.php 入口文件 class 类存放的文件

2、夹 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 存放控制类的文件夹 confi

3、g.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 );?六. 基类函数包含了常用的功能

4、base.class.phppath_root =PATH_ROOT;this-path_class =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*

5、/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:

6、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 Smarttem

7、plate(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();/retur

8、n 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-ass

9、ign(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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号