基本差不多了,正在制作HTML模板部分。贴点代码算了,牛皮一点应该可以说 PHP MVC CLASS OOP 面向对象、应用程序有机的分成三个协作的部份: 模型,视图和控制器。视图是直接面向用户使用的部份。它格式化数据使数据以各种形式展现在荧屏上。然而实际上,它不包含数据。数据包容在模型中。最后,控制器部分接受用户操作命令进而修正模型内的数据 MVC系统中的模型从概念上可以分为两类――系统的内部状态和改变系统状态的动作。模型是你所有的商业逻辑代码片段所在。本文为模型提供了业务实体对象和业务处理对象:所有的业务处理对象都是从ProcessBase类派生的子类。业务处理对象封装了具体的处理逻辑,调用业务逻辑模型,并且把响应提交到合适的视图组件以产生响应。业务实体对象可以通过定义属性描述客户端表单数据。所有业务实体对象都EntityBase派生子类对象,业务处理对象可以直接对它进行读写,而不再需要和request、response对象进行数据交互。通过业务实体对象实现了对视图和模型之间交互的支持。实现时把"做什么"(业务处理)和"如何做"(业务实体)分离。这样可以实现业务逻辑的重用。
$app = new App(); $app->parse(); $app->go(); INDEX.PHP www.shengfang.org <?php session_start(); www.shengfang.org /*------------------------------------- * Application.php * * 用来实现网站的统一入口,调用Controler类 * -------------------------------------*/ class App { //用来记录所要进行的操作 var $action; www.shengfang.org //controler文件的路径名 var $controlerFile; //controler的类名 var $controlerClass; var $method=""; function Application() { } www.shengfang.org function parse() { $this->_parsePath(); $this->_getControlerFile(); $this->_getControlerClassname(); } /* www.shengfang.org * 解析当前的访问路径,得到要进行动作 */ function _parsePath() { global $db,$action; list($path, $param) = explode("?", $_SERVER["REQUEST_URI"]); //echo $param."<br>".$path."<br>"; //$pos = strpos($param, "="); //$m=substr($param, $pos+1); //print_r($m); $m=$action; $login_sess=$_SESSION["login_sess"]; $username_=$db->GetParam("username"); $password_=$db->GetParam("password"); if($login_sess["name"]!=$username_&line;&line;$login_sess["pass"]!=$password_) { www.shengfang.org if($m!="login_chk") { $m="login_login"; } else { $m="login_chk"; } } else www.shengfang.org { $login_sess["name"]=$username_; $login_sess["pass"]=$password_; } //$m="cata_add"; list($this->action,$this->method)=explode("_", $m); } /* www.shengfang.org * 通过动作$action,解析得到该$action要用到的controler文件的路径 */ function _getControlerFile() { $this->controlerFile = "./ctrl/cls".$this->action.".php"; if(!file_exists($this->controlerFile)) www.shengfang.org die("Controler文件名(".$this->controlerFile.")解析错误"); require_once $this->controlerFile; } /* * 通过动作$action,解析得到该$action要用到的controler类名 */ function _getControlerClassname() { $this-> www.shengfang.org controlerClass = "cls".$this->action; if(!class_exists($this->controlerClass)) die("Controler类名(".$this->controlerClass.")解析错误"); } www.shengfang.org /* * 调用controler,执行controler的动作 */ function go() { www.shengfang.org global $tools; if (empty($this->action) && empty($this->method)) { www.shengfang.org $tools->index(); //require"./doc/header.html"; echo"请从右边选择管理选项"; exit(); } [hide] $c = new $this->controlerClass($this->method); [/hide] exit; 本来用的是IF ELSE,我改为SWITCH,最后又改为CLASS, $c->do(); switch ($this->method) { case "": $c->Show(); break; case "login": $c->login(); break; case "logout": $c->logout(); break; case "chk": $c->chk(); break; case "cata": $c->cata(); break; case "add": $c->addcata(); break; case "del": $c->delcata(); break; case "edit": $c->editcata(); break; default: $c->Show(); break; } } } ?> 字体:大 中 小 |