目录
以及文件夹里面详细目录




back/controller里面的 AdminController.class.php 代码
<?php //后台首页控制器 session_start(); class AdminController extends PlatFromController{ function indexAction(){ require VIEW_PATH."index.html"; } function topAction(){ require VIEW_PATH."top.html"; } function menuAction(){ require VIEW_PATH."menu.html"; } function mainAction(){ require VIEW_PATH."main.html"; } function categoryListAction(){ require VIEW_PATH."categoryList.html"; } function goodslistAction(){ //实例化模型类 返回数据 $goodsModel=Factory::M("GoodsModel"); //返回数据 $list=$goodsModel->getList(); require VIEW_PATH."goodslist.html"; } //添加商品 function goodsAddAction(){ require VIEW_PATH."goodsAdd.html"; } //删除商品 function delAction(){ $id=$_GET[id]; //实例化商品模型 $goodsModel=Factory::M("GoodsModel"); //调用删除方法 $goodsModel->delData($id); //显示页面 $list=$goodsModel->getList(); require VIEW_PATH."goodslist.html"; } }
back/controller里面的 GoodsController.class.php 代码
<?php //商品控制器 class GoodsController extends PlatFromController{ //添加商品 function insertAction(){ //收集表单数据 $data["goods_name"]=$_POST["goods_name"]; $data["shop_price"]=$_POST["shop_price"]; $data["goods_number"]=$_POST["goods_number"]; //上传商品图片原图 $t_upload = new Upload(); $t_upload->upload_path = './web/upload/'; $t_upload->prefix = 'goods_ori'; if ($result = $t_upload->uploadOne($_FILES['goods_img'])) { //成功 $data['goods_img'] = $result; } else { //上传失败 $this->_jump('index.php?p=back&c=Admin&a=goodsAdd', '上传失败,<br>' . $t_upload->getError()); } //获取模型对象 $goodsModel=Factory::M("GoodsModel"); //调用模型对象添加方法 $goodsModel->addData($data); //显示页面 $this->_jump("index.php?p=back&c=Admin&a=goodsAdd","添加成功"); require VIEW_PATH."goodsAdd.html"; } }
back/controller里面的 LoginController.class.php 代码
<?php //登录的控制器 class LoginController extends PlatFromController{ //登录表单动作 public function loginAction(){ //载入当前的视图层模板 require VIEW_PATH."login.html"; } //登录验证 function checkAction(){ $uid=$_POST["uid"]; $pwd=$_POST["pwd"]; $yzm=$_POST["yzm"]; $Captcha=new Captcha(); if(!$Captcha->checkCaptcha($yzm)){ $this->_jump("index.php?p=back&c=Login&a=login","验证码错误"); } //连接数据库 把账号密码传过去 验证 $userModel = Factory::M("UserModel"); //根据返回结果 跳转 if($userModel->check($uid,$pwd)){ //登录成功 session_start(); $_SESSION["login"]="yes"; $this->_jump("index.php?p=back&c=Admin&a=index"); }else{ //登录失败 $this->_jump("index.php?p=back&c=Login&a=login","登录失败"); } } //输出验证码 function CaptchaAction(){ $yzm=new Captcha(); $yzm->generate(); } //退出 动作 function quitAction(){ unset($_SESSION["login"]); $this->_jump("index.php?p=back&c=Login&a=login"); } }
back/controller里面的 PlatFromController.class.php 代码
<?php //平台控制器类 集中验证 class PlatFromController extends Controller{ //构造方法 function __construct(){ parent::__construct(); $this->_checkLogin(); } //验证登录操作 function _checkLogin(){ session_start(); //不需要验证的方法 $no_list=array( "Login" =>array("login","check","Captcha") ); //判断不需要验证 //控制器名=》当前控制器不需要验证的动作名列表组 if(isset($no_list[CONTROLLER])&& in_array(ACTION,$no_list[CONTROLLER])){ return; } //需要验证的 if(!isset($_SESSION["login"])){ $this->_jump("index.php?p=back&c=Login&a=login","非法登录-请登录",5); } } }
back/model里面的 GoodsModel.class.php 代码
<?php //商品列表模型 class GoodsModel extends Model{ //获取列表 function getList(){ $sql="select goods_id,goods_name,shop_price,goods_number from p34_goods"; return $this->dao->getAttr($sql); } //添加数据 function addData($data){ $sql="insert into p34_goods(goods_name,shop_price,goods_number)values('".$data['goods_name']."','".$data['shop_price']."','".$data['$goods_number']."')"; $this->dao->DbQuery($sql); } //删除数据 function delData($id){ $sql="delete from p34_goods where goods_id='$id'"; $this->dao->DbQuery($sql); } }
back/model里面的 UsersModel.class.php 代码
<?php //用户表的模型类 class UserModel extends Model{ //登录验证的方法 function check($uid,$pwd){ $sql="select pwd from user where id='$uid'"; $res=$this->dao->getStr($sql); if($pwd != "" && $res != "" && $res ==$pwd){ return true; }else{ return false; } } }
view里面就只弄(index.html login.html )
index.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>
<title>ECSHOP 管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="Text/Javascript" language="JavaScript">
if (window.top != window) {
window.top.location.href = document.location.href;
}
</script>
<frameset rows="76,*" framespacing="0" border="0">
<frame src="index.php?p=back&c=Admin&a=top" id="header-frame" name="header-frame" frameborder="no" scrolling="no">
<frameset cols="180,*" framespacing="0" border="0" id="frame-body">
<frame src="index.php?p=back&c=Admin&a=menu" id="menu-frame" name="menu-frame" frameborder="no">
<frame src="index.php?p=back&c=Admin&a=main" id="main-frame" name="main-frame" frameborder="no">
</frameset>
</frameset><noframes></noframes>
</head>
<body>
</body>
</html>
login.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>
<title>ECSHOP 管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="web/Styles/general.css" rel="stylesheet" type="text/css" />
<link href="web/Styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body style="background: #278296;color:white">
<form method="post" action="index.php?p=back&c=Login&a=check">
<table cellspacing="0" cellpadding="0" style="margin-top:100px" align="center">
<tr>
<td>
<img src="web/Images/login.png" width="178" height="256" border="0" alt="ECSHOP" />
</td>
<td style="padding-left: 50px">
<table>
<tr>
<td>管理员姓名:</td>
<td>
<input type="text" name="uid" />
</td>
</tr>
<tr>
<td>管理员密码:</td>
<td>
<input type="password" name="pwd" />
</td>
</tr>
<tr>
<td>验证码:</td>
<td>
<input type="text" name="yzm" class="capital" />
</td>
</tr>
<tr>
<td colspan="2" align="right">
<img src="index.php?p=back&c=Login&a=Captcha" onClick="this.src='index.php?p=back&c=Login&a=Captcha&'+Math.random()">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="checkbox" value="1" name="remember" id="remember" />
<label for="remember">请保存我这次的登录信息。</label>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" value="进入管理中心" class="button" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type="hidden" name="act" value="signin" />
</form>
</body>
config里面的 application.config.php 代码
<?php
return array(
//数据库配置
"db" =>array(
"host"=>"localhost",
"name"=>"root",
"pwd"=>"",
"DbName"=>"z_075mvc",
"charset"=>"utf8",
"post" =>3306
),
//默认平台
"app" =>array(
"plat"=>"back",
),
//后台默认控制器和方法
"back" =>array(
"controller"=>"Login",
"action"=>"login"
),
//前台默认控制器和方法
"front" =>array(
"controller"=>"Login",
"action"=>"login"
),
//后台默认控制器和方法
"test" =>array(
"controller"=>"Match",
"action"=>"list"
)
);
test/controller里面的 MatchController.class.php 代码
<?php //队伍控制器 class MatchController extends Controller{ //显示比赛列表 function listAction(){ $MatchModel=Factory::M("MatchModel"); $match_list=$MatchModel->getlist(); require VIEW_PATH."match_list_v.html"; } //修改比赛列表 function updateAction(){ echo "这是修改比赛的方法"; } }
test/controller里面的 TeamController.class.php 代码
<?php //队伍控制器 class TeamController extends Controller{ //显示队伍列表 function listAction(){ $TeamModel=Factory::M("TeamModel"); $team_list=$TeamModel->getlist(); require VIEW_PATH."myview.html"; } //删除队伍 function removeTeamAction(){ $id=$_GET["id"]; $TeamModel=Factory::M("TeamModel"); $team_list=$TeamModel->del($id); $team_list=$TeamModel->getlist(); require VIEW_PATH."myview.html"; } }
test/modelr里面的 MatchModel.class.php 代码
<?php class MatchModel extends Model{ function getlist(){ //获得比赛列表数据 $sql = "select t1.t_name as t1_name, m.t1_score, m.t2_score, t2.t_name as t2_name, m.m_time from `match` as m left join `team` as t1 ON m.t1_id = t1.t_id left join `team` as t2 ON m.t2_id=t2.t_id"; return $this->dao->getAssoc($sql); } }
test/modelr里面的 TeamModel.class.php 代码
<?php class TeamModel extends Model{ function getlist(){ $sql="select *from team"; return $this->dao->getAssoc($sql); } function del($id){ $sql="delete from team where t_id=$id"; $this->dao->DbQuery($sql); } }
view里面的 match-list_v.html 代码
<!-- 利用HTML代码展示数据 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>比赛列表</title>
</head>
<body>
<table>
<tr>
<th>球队一</th>
<th>比分</th>
<th>球队二</th>
<th>时间</th>
</tr>
<?php foreach($match_list as $row) : ?>
<tr>
<td><?php echo $row['t1_name'];?></td>
<td><?php echo $row['t1_score'];?>:<?php echo $row['t2_score'];?></td>
<td><?php echo $row['t2_name'];?></td>
<td><?php echo date('Y-m-d H:i', $row['m_time']);?></td>
</tr>
<?php endForeach;?>
</table>
</body>
</html>
view里面的 myview.html 代码
<!-- 利用HTML代码展示数据 --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>比赛列表</title> </head> <body> <table> <tr> <th>t_id</th> <th>t_name</th> <th>操作</th> </tr> <?php foreach($team_list as $row) : ?> <tr> <td><?php echo $row['t_id'];?></td> <td><?php echo $row['t_name'];?></td> <td> <a href="index.php?p=test&c=Team&a=removeTeam&id=<?php echo $row['t_id'];?>">删除</a> </td> </tr> <?php endForeach;?> </table> </body> </html>
framework/tool里面的 Captcha.class.php 代码
<?php
/**
* 验证码 工具
*/
class Captcha {
/**
* 输出生成的验证码输出
*
* @param $code_len=4 码值的长度
* @return void
*/
public function generate($code_len=4) {
//生成码值
$chars = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';//所有可能字符
$chars_len = strlen($chars);
$code = '';//初始化码值字符串
for($i=1; $i<=$code_len;++$i) {
$rand_index = mt_rand(0, $chars_len-1);
$code .= $chars[$rand_index];//字符串支持[]操作,通过下标取得某个字符
}
//echo $code;
//存储于session,用于验证
@session_start();//保证session机制一定是开启的,同时重复开启不会报错,@屏蔽错误。
$_SESSION['captcha_code'] = $code;
//生成验证码图片
//背景图
$bg_file = TOOL_PATH . 'captcha/captcha_bg' . mt_rand(1, 5) . '.jpg';
//基于jpg格式的图片创建画布
$img = imageCreateFromJPEG($bg_file);
//随机分配字符串颜色
$str_color = mt_rand(1, 3) == 1 ? imageColorAllocate($img, 0, 0, 0) : imageColorAllocate($img, 0xff, 0xff, 0xff);
//字符串
$font = 5;
// 画布尺寸
$img_w = imageSX($img);
$img_h = imageSY($img);
// 字体的尺寸
$font_w = imageFontWidth($font);
$font_h = imageFontHeight($font);
// 字符串的尺寸
$code_w = $font_w * $code_len;
$code_h = $font_h;
$x = ($img_w-$code_w)/2;
$y = ($img_h-$code_h)/2;
imageString($img, $font, $x, $y, $code, $str_color);
//输出
header('Content-Type: image/jpeg;');
imageJPEG($img);
//
imageDestroy($img);
}
/**
* 验证
* @param $request_code 用户表单中提交的码值
* @return bool 是否匹配
*/
public function checkCaptcha($request_code) {
@session_start();
//严格点,存在且相等(不区分大小写)。
//strCaseCmp()不区分大小写字符串比较,返回值负,第一个小,返回正,第一个大,返回0,相等。strCmp也是类似,不过是区分大小写比较。
$result = isset($request_code) && isset($_SESSION['captcha_code']) && (strCaseCmp($request_code, $_SESSION['captcha_code'])==0);
//安全考虑,销毁session中的验证码值
unset($_SESSION['captcha_code']);
return $result;
}
}
framework/tool里面的 Upload.class.php 代码
<?php
class Upload {
private $_max_size;
private $_type_map;
private $_allow_ext_list;
private $_allow_mime_list;
private $_upload_path;
private $_prefix;
private $_error;//当前的错误信息
public function getError() {
return $this->_error;
}
public function __construct() {
$this->_max_size = 1024*1024;
$this->_type_map = array(
'.png' => array('image/png', 'image/x-png'),
'.jpg' => array('image/jpeg', 'image/pjpeg'),
'.jpeg' => array('image/jpeg', 'image/pjpeg'),
'.gif' => array('image/gif'),
);
$this->_allow_ext_list = array('.png', '.jpg');
$allow_mime_list = array();
foreach($this->_allow_ext_list as $value) {
//得到每个后缀名
$allow_mime_list = array_merge($allow_mime_list, $this->_type_map[$value]);
}
// 去重
$this->_allow_mime_list = array_unique($allow_mime_list);
$this->_upload_path = './';
$this->_prefix = '';
}
public function __set($p, $v) {//属性重载
$allow_set_list = array('_upload_path', '_prefix', '_allow_ext_list', '_max_size');
//可以不加:_ 进行设置
if(substr($p, 0, 1) !== '_') {
$p = '_' . $p;
}
$this->$p = $v;
}
/**
* 上传单个文件
*/
public function uploadOne($tmp_file) {
# 是否存在错误
if($tmp_file['error'] != 0) {
$this->_error = '文件上传错误';
return false;
}
# 尺寸
if ($tmp_file['size'] > $this->_max_size) {
$this->_error = '文件过大';
return false;
}
# 类型
# 保证修改允许的后缀名,就可以影响到$allow_ext_list和$allow_mime_list
# 设置一个后缀名与mime的映射关系
# 后缀,从原始文件名中提取
$ext = strtolower(strrchr($tmp_file['name'], '.'));
if (!in_array($ext, $this->_allow_ext_list)) {
$this->_error = '类型不合法';
return false;
}
# MIME, type元素。
// $allow_mime_list = array('image/png', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
if (!in_array($tmp_file['type'], $this->_allow_mime_list)) {
$this->_error = '类型不合法';
return false;
}
//PHP自己获取文件的mime,进行检测
$finfo = new Finfo(FILEINFO_MIME_TYPE);//获得一个可以检测文件MIME类型信息的对象
$mime_type = $finfo->file($tmp_file['tmp_name']);//检测
if (!in_array($mime_type, $this->_allow_mime_list)) {
$this->_error = '类型不合法';
return false;
}
# 移动
# 上传文件存储地址
//创建子目录
$subdir = date('YmdH') . '/';
if(!is_dir($this->_upload_path . $subdir)) {//检测是否存在
//不存在
mkdir($this->_upload_path . $subdir);
}
# 科学起名
$upload_filename = uniqID($this->_prefix, true) . $ext;
if (move_uploaded_file($tmp_file['tmp_name'], $this->_upload_path . $subdir . $upload_filename)) {
// 移动成功,返回文件名
return $subdir . $upload_filename;
} else {
// 移动失败
$this->_error = '移动失败';
return false;
}
}
}
frameworkl里面的 Controller.class.php 代码
<?php
//基础控制器
class Controller{
function __construct(){
$this->_initHead();
}
//设置字符集
function _initHead(){
header('Content-Type: text/html; charset=utf-8');
}
//跳转
//@param $url 路径
//@param $info 提示信息
//@param $wait 等待时间
//return void
function _jump($url,$info=null,$wait=3){
if(is_null($info)){
//立即
header("location:".$url);
}else{
//提示后
header("Refresh:$wait;URL=$url");
echo $info;
}
//终止
die;
}
}
frameworkl里面的 Factory.class.php 代码
<?php
//单例工厂类
class Factory{
//返回指定类的对象
public static function M($model_name){
//定义一个数组 用来各种对象
static $model_list=array();
//判断数组中有没有指定的对象
if(!isset($model_list[$model_name])){
$model_list[$model_name]=new $model_name;
}
//返回对象
return $model_list[$model_name];
}
}
frameworkl里面的 Framework.class.php 代码 (很重要 框架类)
<?php //框架初始化功能类 class Framework{ //入口 public static function run(){ //声明路径常量 static::_initPath(); //获取配置信息 static::_initConfig(); //确定分发参数 static::_initParam(); //当前平台相关的路径常量 static::_initPlatPath(); //注册自动加载 static::_initAutoload(); //请求分发 static::_dispatch(); } //声明路径常量 static function _initPath(){ //目录常量 define("ROOT_PATH",getcwd()."/"); define("APP_PATH",ROOT_PATH."application/"); define("FRAME_PATH",ROOT_PATH."framework/"); define("CONFIG_PATH",APP_PATH."config/"); define("TOOL_PATH",FRAME_PATH."tool/"); } //获取配置信息 static function _initConfig(){ $GLOBALS["config"]=require CONFIG_PATH."application.config.php"; } //确定分发参数 static function _initParam(){ //参数分发 平台 //定义平台常量 define("PLATFORM",isset($_GET["p"])?$_GET["p"]:$GLOBALS["config"]["app"]["plat"]); //参数分发 控制器 //定义控制器常量 define("CONTROLLER",isset($_GET["c"])?$_GET["c"]:$GLOBALS["config"][PLATFORM]["controller"] ); //参数分发 动作 //定义动作常量 define("ACTION",isset($_GET["a"])?$_GET["a"]:$GLOBALS["config"][PLATFORM]["action"] ); } //当前平台相关的路径常量 static function _initPlatPath(){ //当前平台相关常量 define("CONTROLLER_PATH",APP_PATH.PLATFORM."/controller/"); define("MODEL_PATH",APP_PATH.PLATFORM."/model/"); define("VIEW_PATH",APP_PATH.PLATFORM."/view/"); } //注册自动加载 static function _initAutoload(){ //注册自动加载方法 spl_autoload_register(array(__CLASS__,"userAutoload")); } //自动加载的方法 自动载入已知类文件 static function userAutoload($class_name){ //先确定确定的(核心类) //类名与类文件映射数组 $framework_class_list=array( //类名=>类文件地址 "Controller" => FRAME_PATH."Controller.class.php", "Model" => FRAME_PATH."Model.class.php", "Factory" => FRAME_PATH."Factory.class.php", "mysqlDb" => FRAME_PATH."mysqlDb.class.php", "Captcha" => TOOL_PATH."Captcha.class.php", "Upload" => TOOL_PATH."Upload.class.php" ); //加载类 if(isset($framework_class_list[$class_name])){ //是核心类 require $framework_class_list[$class_name]; }else if(substr($class_name,-10)=="Controller"){ require CONTROLLER_PATH.$class_name.".class.php"; }else if(substr($class_name,-5)=="Model"){ require MODEL_PATH.$class_name.".class.php"; } } //请求分发 static function _dispatch(){ $controllerName=CONTROLLER."Controller";//组织控制器名 $Action=ACTION."Action";//组织方法名 $controller=new $controllerName(); $controller->$Action(); } }
frameworkl里面的 Model.class.php 代码
<?php
//基础模型类
class Model{
public $dao;//代表mysqlDb类对象
//实例化模型对象时自动创建 mysqlDb对象
function __construct(){
$this->_initDao();
}
//初始化数据库操作类的对象
function _initDao(){
$config=$GLOBALS["config"]["db"];
$this->dao= mysqlDb::getInstance($config);
}
}
frameworkl里面的 mysqDb.class.php 代码(用类封装一个连接数据库的方法)
<?php
class mysqlDb{
public $host; //服务器地址
public $post=3306; //端口
public $name; //用户名
public $pwd; //m密码
public $DbName; //数据库名称
public $charset;//默认编码
public $link;//数据库连接对象
public $res; //资源 返回结果集
//三私一公
private static $obj;//用来存newdb对象
//构造方法 私有的
private function __construct($config=array()){
/*初始化参数*/
$this->host = $config["host"] ? $config["host"] : "localhost";
$this->name = $config["name"] ? $config["name"] : "root";
$this->pwd = $config["pwd"] ? $config["pwd"] : "";
$this->DbName = $config["DbName"] ? $config["DbName"] : "mysql";
$this->charset = $config["charset"] ?$config["charset"] : "utf8" ;
/*连接数据库 设置字符集*/
$this->connectMysql();
$this->setCharSet();
}
//私有化clone方法
private function __clone(){}
//提供公共的返回对象方法
static function getInstance($config=array()){
if(!isset(self::$obj)){
self::$obj=new self($config);
}
return self::$obj;
}
/*连接数据库*/
function connectMysql(){
$this->link = new MySQLi($this->host,$this->name,$this->pwd,$this->DbName);
!mysqli_connect_error() or die("连接数据库失败");
}
/*设置字符集*/
function setCharSet(){
$this->link->query("set names ".$this->charset );
}
/*执行sql语句的方法*/
function DbQuery($sql){
$this->res = $this->link->query($sql);
if(!$this->res){
echo ("<br />执行失败。");
echo "<br />失败的sql语句为:" . $sql;
echo "<br />出错信息为:" . mysqli_error($this->link);
echo "<br />错误代号为:" . mysqli_errno($this->link);
die;
}
return $this->res;
}
//返回字符串
function getStr($sql){
$zhi = $this->DbQuery($sql);
//将结果集转为字符串
$arr = $zhi->fetch_all();
$brr = array();
foreach($arr as $v){
$brr[] = implode(",",$v);
}
return implode("^",$brr);
}
//返回json
function getJson($sql){
$zhi = $this->DbQuery($sql);
$brr = array();
while($row = $zhi->fetch_assoc()){
$brr[] = $row;
}
return json_encode($brr);
}
/*返回关联数组*/
function getAssoc($sql){
$zhi = $this->DbQuery($sql);
$brr = array();
while($row = $zhi->fetch_assoc()){
$brr[] = $row;
}
return $brr;
}
//返回索引数组
function getAttr($sql){
$zhi = $this->DbQuery($sql);
return $zhi->fetch_all();
}
}
web里面的照片 js styles upload(文件上传照片储存文件夹)

index.php (非常重要的 入口文件)
<?php
require "./framework/Framework.class.php";
Framework::run();
更加详细的代码 在D:wampserverwampwww20181012 wanzheng MVC