(1)目录关系展示:
然后我的Factory.class.php文件展示:
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: Interact 5 * Date: 2017/8/19 6 * Time: 21:13 7 * 8 * 项目中的工厂类 9 */ 10 class Factory { 11 /** 12 * 生成模型的单例对象 13 * @param $model_name string 14 * @return object sssssss 15 */ 16 public static function M($model_name) { 17 static $model_list = array(); 18 19 //存储已经实例化好的模型对象得列表,下标是模型名,值是模型对象 20 //判断当前模型是否实例化 21 if (!isset($model_list[$model_name])) { 22 //没有实例化过 23 24 // require MODEL_PATH.$model_name.'.class.php'; 25 26 27 28 $model_list[$model_name] = new $model_name();//实例化对象 29 } 30 31 return $model_list[$model_name]; 32 } 33 }
我的AdminC.controller.class.php展示:
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: Interact 5 * Date: 2017/8/20 6 * Time: 14:22 7 */ 8 class AdminC extends Controller{ 9 public function login(){ 10 // require 11 require APPLICATION_PATH.'back/view/login.html'; 12 } 13 /** 14 * 验证管理员是否合法 15 */ 16 public function check() { 17 // echo "MC天佑MC天佑MC天佑"; 18 // echo $_REQUEST['username']; 19 // 获得表单数据 20 /*echo $_REQUEST['username']; 21 echo ' '; 22 echo $_REQUEST['password'];*/ 23 $admin_name = $_REQUEST['username']; 24 $admin_pass = $_REQUEST['password']; 25 26 27 28 //从数据库中验证管理员信息是否存在合法 29 $m_admin = Factory::M('AdminModel'); 30 if ($m_admin->check($admin_name, $admin_pass)) { 31 //验证通过,合法 32 echo '合法,直接跳转到后台首页'; 33 } else { 34 // 非法 35 echo '非法, 提示,跳转到后台登陆页面index.php?p=back&c=Admin&a=login'; 36 } 37 // 38 } 39 }
login.html代码展示:
1 <html xmlns="http://www.w3.org/1999/xhtml"><head> 2 <title>ECSHOP 管理中心</title> 3 <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> 4 <link type="text/css" rel="stylesheet" href="web/back/styles/general.css"> 5 <link type="text/css" rel="stylesheet" href="web/back/styles/main.css"> 6 7 <style type="text/css"> 8 body { 9 color: white; 10 } 11 </style> 12 </head> 13 <body style="background: #278296"> 14 <form onsubmit="" name="theForm" action="index.php?p=back&c=AdminC&a=check" method="post"> 15 <table cellspacing="0" cellpadding="0" align="center" style="margin-top: 100px"> 16 <tbody><tr> 17 <td><img border="0" width="178" height="256" alt="ECSHOP" src="web/back/images/login.png"></td> 18 <td style="padding-left: 50px"> 19 <table> 20 <tbody><tr> 21 <td>管理员姓名:</td> 22 <td> 23 <label> 24 <input type="text" name="username" id="username"> 25 </label> 26 </td> 27 </tr> 28 <tr> 29 <td>管理员密码:</td> 30 <td> 31 <label> 32 <input type="password" name="password"> 33 </label> 34 </td> 35 </tr> 36 <!-- 37 <tr> 38 <td>验证码:</td> 39 <td><input type="text" class="capital" name="captcha"></td> 40 </tr> 41 <tr> 42 <td align="right" colspan="2"><img border="1" width="145" height="20" title="看不清?点击更换另一个验证码。" style="cursor: pointer;" onclick="this.src="index.php?act=captcha&"+Math.random()" alt="CAPTCHA" src="index.php?act=captcha&1533540459"> 43 </td> 44 </tr> 45 --> 46 <tr><td colspan="2"><input type="checkbox" id="remember" name="remember" value="1"><label for="remember">请保存我这次的登录信息。</label></td></tr> 47 <tr><td> </td><td><input type="submit" class="button" value="进入管理中心"></td></tr> 48 <tr> 49 <td align="right" colspan="2">» <a style="color:white" href="index.php?p=front">返回首页</a> » <a style="color:white" href="index.php?p=back&c=AdminC&a=forget_pwd">您忘记了密码吗?</a></td> 50 </tr> 51 </tbody></table> 52 </td> 53 </tr> 54 </tbody></table> 55 </form> 56 </body></html>
结果展示:
然后结果是: