Simple mvc mode instance

Source: Internet
Author: User
The LyndaMVC mode has many advantages, including single-point control, code separation, rapid development, easy maintenance and expansion in the future, and clear code architecture. None? Phpmvcpattern single-point control simple controller cclassnumbercontrollerextendsdefacontroller controller {public $ modelnull; publicfunction _ const

The Lynda MVC model has many advantages, including single-point control, code separation, rapid development, easy maintenance and expansion in the future, and clear code architecture. None? Php // mvc pattern single-point control // simple controller Cclass NumberController extends defacontroller controller {public $ model = null; public function _ const

Lynda
The MVC mode has many advantages, including single-point control, code separation, rapid development, easy maintenance and extension at the later stage, and clear code architecture. <无>
  Model = NumberModel ();} // Vpublic function view ($ value = 0) {echo "The square of this number is :", $ this-> model-> square ($ value) ;}// controller's base class DefaultController {public function run ($ action = 'index', $ id = 0) {if (! Method_exists ($ this, $ action) {$ action = 'index';} return $ this-> $ action ($ id );} // simple output template public function index () {$ html = ""; for ($ I = 1; $ I <10; $ I ++) {$ html. = sprintf ('
  • ', $ I, "INDEX _ $ I");} echo sprintf ("
      % S
    ", $ Html) ;}}// a very simple model that calculates the area of the Quadrilateral Mclass NumberModel {public function square ($ number) {return $ number * $ number ;}} // GET the controller, model, and parameter $ action = isset ($ _ GET ['a'])? $ _ GET ['a']: 'index'; $ module = isset ($ _ GET ['M'])? $ _ GET ['M']: ''; $ id = isset ($ _ GET ['id'])? $ _ GET ['id']: ''; // find our controller switch ($ module) {case 'number': $ controller = new NumberController (); break; default: $ controller = new DefaultController (); break ;}//
  • Index_1
  • $ Controller-> run ($ action, $ id );

    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.