Mvc is the only thing that can be written. I did not want to write it in this way. Really annoying. I have several directories, such as the model directory and core directory (database class ). Then I write a controller, use the simplest switch to determine the model to be queried, and then add a smarty when V. The general code is mvc. I'm sorry, sorry.
I wouldn't have done it, but I was too inclined to write it like this. Really annoying.
I have several directories, such as the model directory and core directory (database class ).
Then I write a controller, use the simplest switch to determine the model to be queried, and then add a smarty when V.
The general code seems to be
PHP code
switch($action){ case "add1": $smarty=new Smarty(); $smarty->display("tianjiabumen.tpl"); break; case "del": $id=$_GET['id']; $bm=new bumenmodel(); $bm->id=$id; $bm->delete(); header("location:bumenkongzhiqi.php?action=chaxun"); break;
It's disgusting to include files!
If this is written, it cannot be regarded as MVC --.
------ Solution --------------------
There is a class called controller, which is probably like this.
Class controller {
Function getModel ($ name ){}
Function getView ($ name ){}
.
.
}
Then, each c inherits the controller and uses functions that c will use.
Similarly, the basic model class generally has Database Connection methods, input filtering methods, and other model methods.
Then, if there is a template mvc architecture, such as joomla, The view and the template are differentiated, then the view base class will have a loading Template, load the corresponding model method, and so on.
GetModel ($ modelName)
This function is generally written in this way.
PHP code
class factory(){function __contruct(){$this->models = array();}function & getModel($modelName) {if(!isset($this->models[$modelName])){require("{MODEL_BASEPATH}/{$modelName}");$this->models[$modelName] = new $modelName();}return $this->model[$modelName];}}