PHP Object-oriented page controller

Source: Internet
Author: User

<?PHP/*Page Controller mode: As I understand it, it separates the business logic from the view (usually the easiest way to do this is to mix PHP and HTML code in a file), which is a business logic file that corresponds to a view file. The code example is annotated as follows:*///Page Controller Modenamespace Woo\controller;//business logic file (file name addvenue.php)Abstract classPagecontroller {//base class    Private $request; function__construct () {$request= \woo\base\requestregistry::getrequest ();//get a class that handles user request information through the registry class        if(Is_null($request)){            $request=NewRequest (); }        $this->request =$request; }        Abstract functionprocess (); functionForward$resource){//Jump        include($resource); Exit(0); }        functiongetrequest () {return $this-request; }}classAddvenuecontrollerextendsPagecontroller {//The function of this class is to write a venue data to the database (similar to the data table structure: id,name)    functionprocess () {Try{            $request=$this-getrequest (); $name=$request->getproperty (' Venue_name ');//get the name of the venue that the user submitted            if(Is_null($request->getproperty (' submitted ')) {//determine if the form is submitted or not, jump to add_nenue.php                $request->addfeedback ("Choose a name for the venue"); $this->forward (' add_nenue.php '); } Else if(Is_null($name)){//determine if a form submission has a name                $request->addfeedback ("Name is a required field"); $this->forward (' add_venue.php ');//Jump add_venue.php            }                    $venue=New\woo\domain\venue (NULL,$name);//creating an object adds it to the database, and the internal business logic does not have to delve into it.             $this->forward ("listvenues.php");//add success after jump listvenues.php, that is, a list of data display interface}Catch(Exception $e){            $this->forward (' error.php ');//jump to an error interface        }    }}$controller=NewAddvenuecontroller ();//The process () method that executes this class$controller-process ();? ><?PHP//View file (file name add_venue.php)require_once("woo/base/requestregistry.php");$request= \woo\base\requestregistry::getrequest ();? >Print $request->getfeedbackstring (' </td></tr><tr><td> ')?> </td> </tr> </table&    Gt <form action= "addvenue.php" method= "get" > <input type= "hidden" name= "submitted" value= "Yes"/> & Lt;input type= "text" name= "Venue_name"/> </form></body>

PHP Object-oriented page controller

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.