MVC mode PHP implementation (3)

zhaozj2021-02-16  46

Finally, the controller will implement the view as a subclass.

header (); switch ($ getvars [ 'view']) {case "product ": $ This-> ProductItem ($ getVars ['id']); break; default: IF (Empty ($ getvars ['rownum']) {$ this-> producttable ();} else {$ THIS-> ProductTable ($ getVars ['rownum'];} Break;} $ this-> footer ();}}?>

Note that this is not the only way to implement MVC - such as you can use the controller to implement the model simultaneously integrated view. This is just a method of demo mode.

Our index.php files look like this:

Display ();?>

Beautiful and simple.

We have some techniques using the controller, you can do this in PHP:

$ this -> {$ _ get ['Method']} ($ _ get ['param']);

A suggestion is that you better define the namespace of the program URL, which will compare the specification such as:

"Index.php? class = ProductView & method = ProductITEM & ID = 4" Through it we can handle our controller:

$ View = new $ _GET ['Class']; $ View -> {$ _ get ['Method'] ($ _ get ['id']);

Sometimes, building a controller is a difficult thing, such as when you trade between development speed and adaptability. A good place to get inspiration is the Java Struts of Apache Group, which is defined by the XML documentation. @ 完 程 式 PS: Original is a post; but the death is not going to -________- bless waist, the part1 http://www.9cbs.net/develop/read_article.asp?id=21639 part2 http: // www. 9cbs.net/develop/read_article.asp?id=21640 part3 http://www.9cbs.net/develop/read_article.asp?id=21641

转载请注明原文地址:https://www.9cbs.com/read-25645.html

New Post(0)