PHP object-oriented page controller and php object-oriented Controller
<? Php/* Page controller mode: In my understanding, it is to separate the business logic from the view (usually the simplest way is that php and html code are mixed in a file ), that is, a business logic file corresponds to a View File. The code example is annotated as follows: * // page controller mode namespace woo \ controller; // business logic file (file name AddVenue. php) abstract class PageController {// base class private $ request; function _ construct () {$ request = \ woo \ base \ RequestRegistry: getRequest (); // obtain a class for processing user request information through the registry class if (is_null ($ request) {$ Request = new request ();} $ this-> request = $ request;} abstract function process (); function forward ($ resource) {// jump include ($ resource); exit (0 );} Function getRequest () {return $ this-> request;} class AddVenueController extends PageController {// this class is used to write a venue data to the database (the data table structure is similar to: id, name) function process () {try {$ request = $ this-> getRequest (); $ name = $ request-> getProperty ('venue _ name '); // obtain the name of the venue submitted by the user if (is_null ($ request-> getProperty ('submitted') {// determine whether the form is submitted, otherwise, jump to add_nenue.php $ request-> addFeedback ("choose a name for the venue"); $ thi S-> forward ('add _ nenue. php ');} else if (is_null ($ name) {// determines whether the form is submitted with name $ request-> addFeedback ("name is a required field "); $ this-> forward ('add _ venue. php '); // jump to add_venue.php} $ venue = new \ woo \ domain \ Venue (null, $ name); // create an object to add it to the database, the specific internal business logic does not need to be further explored. $ This-> forward ("ListVenues. php "); // jump to ListVenues after successful addition. php, that is, the display interface of a list of data} catch (Exception $ e) {$ this-> forward ('error. php '); // jump to an error page }}$ controller = new AddVenueController (); // Execute process () for this class () method $ controller-> process ();?> <? Php // View File (file name add_venue.php) require_once ("woo/base/RequestRegistry. php"); $ request = \ woo \ base \ RequestRegistry: getRequest ();?> <Html>