MVC mode PHP implementation (3)

zhaozj2021-02-16  94

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. @ 完整

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

New Post(0)