Finally, the controller will implement the view as a subclass.
Php / ** * Controls the application * / class ProductController extends ProductView {//! A constructor. / ** * Constucts a new ProductController object * @param $ model an instance of the ProductModel class * @param $ getvars the incoming HTTP GET method variables * / function ProductController (& $ model, $ getvars = null) {ProductView :: ProductView ($ model); $ this-> 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:
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. @ 完整