PHP object-oriented page controller and php object-oriented Controller

Source: Internet
Author: User
Tags php print

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> 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.