Our index.php file looks like this:
Here is the code snippet: Require_once (' lib/dataaccess.php '); Require_once (' lib/productmodel.php '); Require_once (' lib/productview.php '); Require_once (' lib/productcontroller.php '); $dao =& new DataAccess (' localhost ', ' user ', ' Pass ', ' dbname '); $productModel =& New ProductModel ($dao); $productController =& New Productcontroller ($productModel, $_get); echo $productController->display (); ?> |
Beautiful and simple.
We have some tips for using the controller, which you can do in PHP:
$this->{$_get[' method ']} ($_get[' param ');
One suggestion is that you better define the namespace form (namespace) of the program URL, so it will compare specifications such as:
Here is the code snippet:
"Index.php?class=productview&method=productitem&id=4"
|
Through it we can handle our controller in this way:
Here is the code snippet:
$view =new $_get[' class '); $view->{$_get[' method '] ($_get[' id ');
|
Sometimes it's hard to build a controller, such as when you weigh the speed and adaptability of your development. A good place to get inspired is the Java Struts of the Apache group, whose controllers are completely defined by the XML document.