Mvc is the only thing that can be written. Younger brother, I'm sorry, sorry.

Source: Internet
Author: User
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];}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.