php skymvc 一款輕量、簡(jiǎn)單的php
mvc框架。歡迎大家多多提些建議。
1.創(chuàng)建配置文件skyMVC支持自動(dòng)創(chuàng)建網(wǎng)站目錄:輸入http://locahost/skymvc/install.php 即可自動(dòng)創(chuàng)建
文件目錄。如果創(chuàng)建之后想重新創(chuàng)建,刪除install.lock文件及可。
推薦自動(dòng)創(chuàng)建。
也可以手動(dòng)創(chuàng)建:目錄都可以自定義
自定義目錄時(shí)需要對(duì)程序進(jìn)行相應(yīng)的配置
admin 后臺(tái)目錄
admin/model
admin/ctrl
attach
上傳的附件目錄
ctrl 控制文件目錄
data 目錄
data/config.php
配置文件
data/cache 緩存目錄
data/cache/css
css緩存
data/cache/file文件緩存
data/cache/tpl 模板緩存
data/cache/js
js緩存
model 模型文件目錄
tpl 模板目錄
tpl/admin 后臺(tái)模板
tpl/default
默認(rèn)模板
js目錄
plugin 插件目錄
admin.php 后臺(tái)入口文件
index.php 前臺(tái)入口文件
2.入口文件
skymvc采用單一入口模式,但不是唯一入口,推薦使用兩個(gè)入口。一個(gè)是前臺(tái)入口,一個(gè)是后臺(tái)入口。
1.前臺(tái)入口文件實(shí)例:index.php 文件名可以自定義 推薦 index 或者
default
<?php
require
"data/config.php";//加載配置文件
require("skymvc/skymvc.php");//引用框架文件
//判斷控制器是否合法
$_GET['m']=isset($_GET['m'])
&&
in_array($_GET['m'],array('index'))?$_GET['m']:'index';
//判斷結(jié)束
require_once(CTRL_DIR."/{$_GET['m']}.ctrl.php");
$classname
= $_GET['m'].'Control';
$control = new
$classname();
//配置偽靜態(tài)的
$control->tpl->rewrite=false;
$control->tpl->rewrite_rule=array(array("/index.php/i"),array("index.html"));
//配置偽靜態(tài)結(jié)束
$method=isset($_GET['a'])
&& method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:"onDefault";
$control->$method();
?>
2.后臺(tái)入口文件:admin.php 文件名可自定義
<?php
require
"data/config.php";
require("skymvc/skymvc.php");
$_GET['m']=isset($_GET['m'])
&&
in_array($_GET['m'],array('index','article'))?$_GET['m']:'index';
require_once(ADMIN_DIR."/".CTRL_DIR."/{$_GET['m']}.ctrl.php");
$classname
= $_GET['m'].'Control';
$control = new
$classname();
//配置偽靜態(tài)的
$control->tpl->tplid="admin";
$control->tpl->currdir="admin";
$control->tpl->rewrite_on=true;
$control->tpl->rewrite_rule=array(array("/index.php/","index.html"));
$method=isset($_GET['a'])
&& method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:"onDefault";
$control->$method()
?>
說明:前后臺(tái)入口文件的差別不大,主要在于 模型 和 控制文件 所在文件夾。
3.控制器文件
<?php
class indexControl extends skymvc
{
function
__construct()
{
$this->indexControl();
}
function
indexControl()
{
parent::__construct();//父類初始化
$this->loadModel("index");
//后臺(tái)
//$this->loadAdminModel("index");
}
function
onDefault()
{
$this->tpl->assign("welcome","歡迎使用skymvc,讓我們共同努力!");
$this->tpl->assign("who",$_ENV['indexModel']->test());
//后臺(tái)
//$this->tpl->assign("who",$_ENV['admin_indexModel']->test());
$this->tpl->display("index");
}
?>
4.模型文件
模型文件主要用于處理數(shù)據(jù),當(dāng)然也可以處理其他的邏輯,但不推薦。文件命名規(guī)范:類.model.php
如:index.model.php.
模型文件位于模型目錄下面:如model目錄
例:index.model.php
<?php
class
indexModel
{
public $base;
function
__construct(&$base)
{
$this->indexModel($base);
}
function
indexModel(&$base)
{
$this->base=$base;
$this->db=$base->db;
}
function
test()
{
echo "這是模型測(cè)試";
}
}
?>
模型文件:前后臺(tái)一樣 就存儲(chǔ)的地方不一樣
5.hello world
kymvc框架的hello word !
如果是自動(dòng)創(chuàng)建目錄的話。
配置好數(shù)據(jù)庫(kù)
index.php
入口文件寫好。
index.php內(nèi)容
<?php
require
"data/config.php";//加載配置文件
require("skymvc/skymvc.php");//引用框架文件
//判斷控制器是否合法
$_GET['m']=isset($_GET['m'])
&&
in_array($_GET['m'],array('index','article'))?$_GET['m']:'index';//將所有在index.php入口出現(xiàn)的模塊都放入array()里
//判斷結(jié)束
require_once(CTRL_DIR."/{$_GET['m']}.ctrl.php");
$classname
= $_GET['m'].'Control';
$control = new
$classname();
$method=isset($_GET['a']) &&
method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:"onDefault";
$control->$method();?>
在ctrl目錄下 創(chuàng)建
hello.ctrl.php 文件
<?php//hellControl 類得命名規(guī)范 類名Control
class
helloControl extends skymvc
{
function __construct()
{
$this->helloControl();
}
function
helloControl()
{
parent::__construct();
$this->loadModel("hello");//載入模型
可以載入任何模型 但不能是相同類的模型
}
//默認(rèn)執(zhí)行的動(dòng)作 命名規(guī)范 on函數(shù)名
function
onDefault()
{
echo "hello world
"; $this->smarty->display("hello.html");
}
//當(dāng)m=hello, a=test
執(zhí)行下面的函數(shù)
function
onTest(){
$this->tpl->assign("test",$_ENV['helloModel']->gettest());
$this->tpl->display("hello.html");
}
}?>
在model目錄下
創(chuàng)建hello.model.php
<?php
class helloModel
{
public
$base;
function
__construct(&$base)
{
$this->helloModel($base);
}
function
helloModel(&$base)
{
$this->base=$base;
$this->db=$base->$db;
}
//上面都是不用改的
function gettest(){
return $this->db->getRow("select * from test
limit 1");//讀取數(shù)據(jù)
}
}
?>
在tpl目錄下 新建 hello.html
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb2312"
/>
<title>無標(biāo)題文檔</title>
</head>
<body>
這是第一個(gè)例子:Hello World !
這是測(cè)試的例子:{loop $test $t} {$t}
{/loop}
</body>
</html>
skymvc 下載地址
- PHP的MVC模式實(shí)現(xiàn)原理分析(一相簡(jiǎn)單的MVC框架范例)
- 基于PHP Web開發(fā)MVC框架的Smarty使用說明
- 有關(guān)PHP中MVC的開發(fā)經(jīng)驗(yàn)分享
- php打造屬于自己的MVC框架
- PHP中MVC模式的模板引擎開發(fā)經(jīng)驗(yàn)分享
- PHP MVC模式在網(wǎng)站架構(gòu)中的實(shí)現(xiàn)分析
- MayFish PHP的MVC架構(gòu)的開發(fā)框架
- PHP實(shí)現(xiàn)MVC開發(fā)得最簡(jiǎn)單的方法——模型
- MVC模式的PHP實(shí)現(xiàn)
- PHP5中MVC結(jié)構(gòu)學(xué)習(xí)
- 淺析PHP程序設(shè)計(jì)中的MVC編程思想
相關(guān)文章
php彈出對(duì)話框?qū)崿F(xiàn)重定向代碼
本為大家介紹下使用php或js彈出對(duì)話框?qū)崿F(xiàn)重定向,具體示例如下,感興趣的朋友不要錯(cuò)過2014-01-01php實(shí)現(xiàn)的證件照換底色功能示例【人像摳圖/換背景圖】
這篇文章主要介紹了php實(shí)現(xiàn)的證件照換底色功能,結(jié)合實(shí)例形式分析了php實(shí)人像摳圖與換背景圖相關(guān)操作技巧,需要的朋友可以參考下2020-05-05PHP stream_context_create()作用和用法分析
創(chuàng)建并返回一個(gè)文本數(shù)據(jù)流并應(yīng)用各種選項(xiàng),可用于fopen(),file_get_contents()等過程的超時(shí)設(shè)置、代理服務(wù)器、請(qǐng)求方式、頭信息設(shè)置的特殊過程。2011-03-03PHP實(shí)現(xiàn)對(duì)xml進(jìn)行簡(jiǎn)單的增刪改查(CRUD)操作示例
這篇文章主要介紹了PHP實(shí)現(xiàn)對(duì)xml進(jìn)行簡(jiǎn)單的增刪改查(CRUD)操作,結(jié)合簡(jiǎn)單實(shí)例形式分析了php針對(duì)xml文件數(shù)據(jù)進(jìn)行載入、修改等相關(guān)操作技巧,需要的朋友可以參考下2017-05-05PHP實(shí)現(xiàn)負(fù)載均衡session共享redis緩存操作示例
這篇文章主要介紹了PHP實(shí)現(xiàn)負(fù)載均衡session共享redis緩存操作,涉及php用戶登陸、session存儲(chǔ)、判斷等相關(guān)操作技巧,需要的朋友可以參考下2018-08-08Yii使用queue實(shí)現(xiàn)隊(duì)列流程講解
Yii是一個(gè)高性能的PHP5的web應(yīng)用程序開發(fā)框架。通過一個(gè)簡(jiǎn)單的命令行工具yiic可以快速創(chuàng)建一個(gè)web應(yīng)用程序的代碼框架,開發(fā)者可以在生成的代碼框架基礎(chǔ)上添加業(yè)務(wù)邏輯,以快速完成應(yīng)用程序的開發(fā)2022-11-11PHP學(xué)習(xí)筆記 (1) 環(huán)境配置與代碼調(diào)試
學(xué)習(xí)php第一步就是需要配置php運(yùn)行環(huán)境,這個(gè)是基礎(chǔ),需要的朋友可以參考下。2011-06-06php字符串比較函數(shù)用法小結(jié)(strcmp,strcasecmp,strnatcmp及strnatcasecmp)
這篇文章主要介紹了php字符串比較函數(shù)用法,結(jié)合實(shí)例形式分析了php針對(duì)字符串的比較、排序等操作相關(guān)技巧與注意事項(xiàng),需要的朋友可以參考下2016-07-07php使用PhpSpreadsheet導(dǎo)出Excel表格的實(shí)例詳解
這篇文章將給大家介紹php使用PhpSpreadsheet導(dǎo)出Excel表格的實(shí)例,文中通過代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-01-01