Example: Demo member Add and delete
Note: Because it is a simple example, we use the screen to print the words "Add success" and "delete success" to indicate the addition and deletion of members , just to demonstrate how to achieve a three-layer separation:
1 if you simply print "Add success" and "delete success" on the screen, it's easy to create a new manage.php directly inside the code below to achieve the effect: There is only one layer, that is, the expression layer , then how to separate it
<? Echo ' add success '; Echo ' Delete succeeded ';? >
2 new Manage.class.php file, as the data layer,manage.php only need to introduce Manage.class.php and instantiate an object, there are two layers
Manage.class.php (Ignoring the constructor method, which is the third step of the connection)
<?PHPclassmanage{ Public function__construct () {NewManageaction ($this); } //New Admin Public functionAddmanage () {returnNew; } Public functionDeletemanage () {returnDelete; } }?>
manage.php instead:
<? PHP // entity class require ' Manage.class.php '; // entrance $_m New Manage (); Echo $_m, Addmanage (); Echo $_m, Deletemanage ();? >
3 Business Logic Layer, new ManageAction.class.php file
<? PHP class manageaction{ publicfunction __construct ($_m) { Echo $_m, Addmanage (); Echo $_m-Deletemanage (); } ? >
manage.php instead: three-layer separation is achieved.
<? PHP // entity class require ' Manage.class.php '; // Business Controller require ' ManageAction.class.php '; // entrance $_m New Manage ();? >
Also: Action.class.php and Model.class.php are base classes for handling redundant three-layer what
See the source file for examples
Demo Example of OPP implementation of three-layer architecture