Introduction to the MVC framework

Source: Internet
Author: User
Tags php language ldap xsl actionlink
<span id="Label3"></p> <dl class="lemmaWgt-lemmaTitle lemmaWgt-lemmaTitle-"> <dd class="lemmaWgt-lemmaTitle-title"> <dl class="lemmaWgt-lemmaTitle lemmaWgt-lemmaTitle-"> <dl class="lemmaWgt-lemmaTitle lemmaWgt-lemmaTitle-"> <dd class="lemmaWgt-lemmaTitle-title"> MVC framework <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">editing</span> </dd> </dl> </dl>The full name of MVC is the model View Controller, which is the abbreviation for the models-view-controller, a software design paradigm that organizes the code with a method of business logic, data, and interface display Separation. Aggregating business logic into a single component does not require rewriting business logic while improving and personalizing the interface and user Interaction. MVC is uniquely developed to map the traditional input, processing, and output functions in a logical graphical user interface Structure. <dl class="basicInfo-block basicInfo-left"> <dl class="basicInfo-block basicInfo-left"> <dt class="basicInfo-item name"> Chinese name </dt> <dd class="basicInfo-item value"> Mvc </dd> <dt class="basicInfo-item name"> Foreign names </dt> <dd class="basicInfo-item value"> MVC Framework </dd> <dt class="basicInfo-item name"> Full Name </dt> <dd class="basicInfo-item value"> Model View Controller </dd> </dl> </dl> <dl class="basicInfo-block basicInfo-right"> <dl class="basicInfo-block basicInfo-right"> <dt class="basicInfo-item name"> Generation time </dt> <dd class="basicInfo-item value"> 1982 </dd> <dt class="basicInfo-item name"> Schema content </dt> <dd class="basicInfo-item value"> view, model, Controller </dd> <dt class="basicInfo-item name"> Category </dt> <dd class="basicInfo-item value"> Software Component Mode </dd> </dl> </dl>Directory <ol> <ol> <li class="level1"><span class="index">1 <span class="text">Introduction</span></span></li> <li class="level1"><span class="index">2 <span class="text">MVC Programming Patterns</span></span></li> <li class="level1"><span class="index">3 <span class="text">Framework Content</span></span></li> <li class="level2"><span class="index">? <span class="text">View</span></span></li> <li class="level2"><span class="index">? <span class="text">Model</span></span></li> <li class="level2"><span class="index">? <span class="text">Controller</span></span></li> </ol> </ol> <ol> <ol> <li class="level1"><span class="index">4 <span class="text"> difference </span> </span> </li> <li class="level1">< Span class= "index" >5 <span class="text"> Common frame </span> </li> <li class="level2"><span class="text" ?  <span>struts </span> </li> <li class="level2"><span class="index">?  <span class="text">spring </span> </span> </li> <li class="level2"><span class="index">? <span class="text">zf </span> </span> </li> <li class="level2"><span class="index">? <span class="text">.net </span> </span> </li> </ol> </ol> <ol> <ol> <li class="level1"><span class="index">6 <span class="text">features</span></span></li> <li class="level2"><span class="index">? <span class="text">Advantages</span></span></li> <li class="level2"><span class="index">? <span class="text">Disadvantages</span></span></li> <li class="level1"><span class="index">7 <span class="text">External evaluation</span></span></li> <li class="level1"><span class="index">8 <span class="text">MVC Controls</span></span></li> </ol> </ol>Brief introduction <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>MVC begins in the desktop program, m refers to the business model, v refers to the user interface, C is the controller, the purpose of using MVC is to separate m and V implementation code, so that the same program can use different representations. For example, a batch of statistical data can be represented by histogram, Pie Chart. C exists to ensure the synchronization of M and v, and once M is changed, v should be updated synchronously. [1-2] Model-view-controller (MVC) is a software design pattern invented by Xerox PARC in the the 1980s for programming language Smalltalk-80, which has been widely used. It was later recommended as a design model for Oracle's Sun Company's Java EE platform and was welcomed by a growing number of developers using ColdFusion and Php. Model-view-controller mode is a useful toolbox that has many benefits, but also has some drawbacks. [3] (overview of content source: [4]) MVC Programming mode <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>MVC is a pattern of creating WEB applications using MVC (model view Controller-view-controller) design: [1] <ul class="custom_dot para-list list-paddingleft-1"> <ul class="custom_dot para-list list-paddingleft-1"> <li class="list-dot list-dot-paddingleft">Model (models) represent the core of the application (such as a list of database records).</li> <li class="list-dot list-dot-paddingleft">View displays data (database records).</li> <li class="list-dot list-dot-paddingleft">The controller (director) processes the input (writes to the database record).</li> </ul> </ul>The MVC pattern also provides complete control over HTML, CSS, and JavaScript. Model is the part of your application that handles application data Logic. <br>typically, Model objects are responsible for accessing data in the Database. View is the part of the application that handles the display of Data. <br>Typically views are created from model Data. A controller is a part of an application that handles user Interaction. <br>Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the Model. MVC layering helps you manage complex applications because you can focus on one aspect at a Time. For example, you can focus on view design without relying on business logic. It also makes testing of applications Easier. The MVC hierarchy also simplifies group Development. Different developers can develop views, controller logic, and business logic at the same time. Framework Content <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>MVC is a framework pattern that makes it mandatory to separate the input, processing, and output of an Application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks. The most typical MVC is the JSP + servlet + JavaBean Pattern. [5] View view is the interface that the user sees and interacts With. For older web applications, views are an interface of HTML elements, and in modern web applications, HTML still plays an important role in the view, but new technologies are emerging, including Adobe Flash and like xhtml,xml/xsl, Some identity languages and web services, such as Wml. The benefit of MVC is that it can handle many different views of the Application. There is really no real processing happening in the view, whether the data is stored online or an employee list, as a view, it is simply a way to output data and allow the user to manipulate it. [6] model models represent enterprise data and business Rules. Of the three parts of mvc, the model has the most processing tasks. For example, It may use a Component object such as EJBS and ColdFusion to process the database, the data returned by the model is neutral, that is, the model is independent of the data format, so that a model can provide data for multiple views, Because the code applied to the model can be reused by multiple views only once, it reduces the repetition of the Code. [6] the controller controller accepts the User's input and invokes the model and view to complete the User's needs, so when you click a hyperlink in a Web page and send an HTML form, the controller itself does not output anything and does any processing. It simply receives the request and decides which model component is called to process the request, and then determines which view to use to display the returned Data. [6] differences <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>The difference between a framework and a design pattern many programmers often confuse frame patterns with design patterns, thinking that MVC is a design pattern. In fact, they are completely different concepts. [7] the two concepts of frame and design pattern are always confusing, but there are still differences between them. Frameworks are often code reuse, while design patterns are reuse, schemas are in between, part of code reuse, partial design reuse, and sometimes analysis can be reused. There are three levels of reuse in software production: internal reuse, an abstract block that can be used publicly in the same application, code reuse, the assembly of common modules into libraries or toolsets for use in multiple applications and domains, and the reuse of application frameworks that provide a common or off-the-shelf infrastructure for specialized areas For the highest level of Reusability. Although the framework is similar to the design pattern, it is fundamentally different. The design pattern is a description of the recurring problems in an environment and the solution to the problem, which is more abstract than the framework, the framework can be expressed in code, can be directly executed or reused, and only instances of the schema can be represented in code; design patterns are smaller elements than frames. A framework often contains one or more design patterns, and the framework is always targeted at a particular application area, but the same pattern can be applied to a variety of applications. It can be said that the framework is software, while design patterns are software Knowledge. What are the framework modes? MVC, MTV, MVP, CBD, orm, etc., What are the frameworks? C + + language qt, MFC, Gtk,java language ssh, ssi,php language smarty (mvc mode), python language Django (mtv Mode) and so on design patterns? Factory mode, Adapter mode, policy mode, etc. in short: the framework is a great wisdom, used for the division of software design, design mode is a small skill, the specific problems proposed solutions to improve code reuse rate, reduce Coupling. Common frameworks <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>Strutsstruts is part of the Jakarta Project under the Apache software Foundation. The main architectural design and developer of the Struts framework is Craig R.mcclanahan. Struts is the undisputed king in the Java Web MVC Framework. After more than nine years of development, struts has grown into a stable, mature framework, and occupies the largest market share in the MVC Framework. But some of Struts's technical features have lagged behind the emerging MVC Framework. With spring MVC, WEBWORK2 These more sophisticated, more scalable frameworks, struts has been challenged as never before. But in terms of product development, struts is still the surest choice. Struts consists of a set of mutually collaborative classes (components), servlets, and JSP tag lib. The Web application based on struts architecture basically conforms to the design standard of JSP Model2, which can be said to be a type of change of MVC design Pattern. Based on the description of the framework, it is easy to understand why struts is a web framework, not just a combination of some tag libraries. But Struts also contains a wealth of tag libraries and utility classes that work independently of the Framework. Struts has its own controller, and incorporates other technologies to implement the model and view layers (views). At the model level, struts can be easily combined with data access techniques, including Ejb,jdbc and object Relation Bridge. In the view layer, struts can be combined with these presentation layer components, such as jsp, Velocity templates,xsl, and so On. [8] springspring is actually a concrete implementation of the design ideas described in the expert one-on-one, the Java EE designs and Development. In one-on-one, Rod Johnson advocates the design of the Java EE Pragmatism and provides a preliminary development framework implementation (INTERFACE21 Development Package) with the BOOK. Spring is a more comprehensive and concrete embodiment of this Idea. On the basis of the INTERFACE21 development package, Rod Johnson has been further transformed and expanded to become a more open, clear, comprehensive and efficient development Framework. Spring is an open-source framework that was created by Rod Johnson and described in his book, "the Java EE design Development programming guide". It is created to address the complexities of enterprise application Development. Spring makes theIt is possible to use basic javabeans to accomplish things that were previously only possible by ejbs. however, the use of spring is not limited to server-side Development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from Spring. In simple terms, Spring is a lightweight control reversal and face-oriented capacitive Framework. of course, This description is a little too simple. But it does outline what spring does. [8] zfzend framework] is a fully PHP5-based open source PHP development framework developed by Zend company, which can be used to develop WEB programs and services, and ZF uses MVC (model–view-controller) Schema mode to detach different parts of the application to facilitate program development and MAINTENANCE. (the detailed use of the MVC framework and its related specific operations can be read in reference:[8]   or extended read second, three, four.) ). net.net mvc[9]   is Microsoft's official, MVC-based,. NET Web application (web Application) framework, which is a monorail from castle ( Castle's Monorail is from java), the latest version is NOW. N 4.5. [10]  Features <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"> edit </span> </span>Advantage coupling low view layer and business layer separation, allowing changes to the view layer code without recompiling the model and controller code, as well, a change in an Application's business process or business rules only needs to alter the MVC model Layer. Because the model is decoupled from the controller and view, it is easy to change the data layer and business rules of the Application. The model is self-contained and detached from the controller and view, so it is easy to change the data layer and business rules of the Application. If you migrate a database from MySQL to oracle, or change an rdbms-based data source to ldap, you can simply change the model. Once the model is implemented correctly, the view will display them correctly, regardless of whether the data is from the database or the LDAP server. Since the three parts of an application using MVC are independent, changing one does not affect the other two, so a good loosely coupled component can be constructed based on this design IDEA. [11]  High reusability as technology progresses, more and more ways are needed to access applications. The MVC pattern allows you to access the same Server-side code using a variety of different styles of view, because multiple views can share a model that includes any web (HTTP) browser or wireless browser (wap), for example, a user can order a product from a computer or via a mobile PHONE. Although the order is not the same way, but the way to deal with the order of products is the Same. Since the data returned by the model is not formatted, the same artifacts can be used by different interfaces. For example, Many of the data may be represented in html, but it is also possible to use WAP to represent the commands required to change the implementation of the view layer without any changes to the control layer and the model Layer. Since data and business rules have been separated from the presentation layer, it is possible to maximize the reuse of Code. The model also has the capability of state management and data persistence processing, for example, session-based shopping carts and e-commerce processes can also be reused by flash sites or wireless networking Applications. [11]  Low life cycle cost MVC reduces the technical content of developing and maintaining user Interfaces. The rapid deployment of the MVC pattern enables a considerable reduction in development time, which allows programmers (java Developers) to focus on business logic and interface Programmers (html and JSP Developers) to focus on Presentation. The Maintainable High-separation view layer and the business logic layer also make Web applications easier to maintain and modify. Advantageous software engineering management because different layers have their own roles, each layer of different applications has some of the same characteristics, which facilitates the application of engineering, tool-based management program Code. The controller also provides the benefit of using a controller to join different models and views to complete the User's needs, so that the controller can provide a powerful means of constructing the Application. Given some reusable models and views, the controller can select the model to process based on the User's needs and then select the view to process the resultsShown to the User. [12-13]  shortcomings It is not easy to fully understand MVC without a clear definition. Using MVC requires careful planning, and because its internal principles are complex, it takes some time to Think. At the same time, due to the strict separation of the model and view, this also brings some difficulties to debug the Application. Each component needs to be thoroughly tested before it can be used. Not suitable for small, medium-sized applications that spend a lot of time applying MVC to applications that are not large in size will often outweigh the costs. Increasing the complexity of the system structure and implementation for a simple interface, strict adherence to mvc, so that the model, view and controller separation, will increase the complexity of the structure, and may generate too much update operations, reduce operational efficiency. Too tightly connected views and controllers are separated from each other, but are tightly connected parts, The view has no controller, its application is very limited, and Vice versa, which hinders their independent reuse. Inefficient access to model data by a view depending on the model operator interface, The view may require multiple calls to obtain sufficient display Data. Unnecessary frequent access to unchanged data will also compromise operational performance. The General Advanced Interface tool or constructor does not support the need for schemas to transform these tools to accommodate MVC needs and to create separate parts at the expense of high, resulting in the difficulty of MVC Use. [12-13]  external evaluation <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>According to Yesky data show: the web-based MVC framework in the world of Java EE has been unprecedented prosperity, TTS website almost every two weeks there will be a new MVC framework released, better mvc, veteran has struts, Webwork. The emerging MVC framework has spring mvc, Tapestry, jsf, and so On. These are mostly works by well-known teams, and there are also some marginal team works, such as dinamica, vraptor, etc., which provide a good level of separation capabilities, on the basis of good MVC separation, by providing some ready-made auxiliary class libraries, It also promotes the improvement of production Efficiency. [8] How to choose a good framework to apply in the project will be critical to the efficiency and reusability of the Project. [8] MVC Control <span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma"><span class="cmn-icon wiki-lemma-icons wiki-lemma-icons_edit-lemma">Edit</span></span>Without its own controls in the asp. NET MVC framework, The page display is completely back to the age of writing HTML Code. fortunately, There are also two helper classes in the Asp. NET MVC framework that bring their own htmlhelper and urlhelper. There are also extensions to help classes in the Mvccontrib extension project, so that we can use these helper classes not only to write the pages we need to display with full html, but also to generate HTML code at the end of the Run. The HtmlHelper class HtmlHelper class is located under the System.Web.MVC.Html namespace. mainly including formextensions,inputextensions, <br>  7 static classes such as linkextensions,selectextensions,textareaextensions,validationextensions,renderpartialextensions, They are all implemented using an outreach Approach. InputExtensions Class: There are 5 types of extension methods, respectively, for the checkbox control, the hidden control, the pass control, Radionbutton Controls and TextBox controls Linkextensions Class: This class is primarily used to generate related links, primarily extending the ActionLink and RouteLink methods. Actionlink: the extension method primarily implements a connection, with a total of 10 overloaded methods. Urlhelper help class to see the class name also knows that this class is used as a URL in an ASP. NET MVC Application. Urlhelper provides four very common four methods. The 1.Action method generates a Url,2.content method by providing controller,action and various parameters to convert a virtual, relative path to the absolute path of the application, and the 3.Encode method is to encrypt the URL address, Same as the Server.encode Method. The 4.RouteUrl method is to provide a URL that matches the routing rules specified in the current Application. There are also two properties, the RequestContext and routecollection two attributes, respectively, that contain the HTTP context and routedata two properties, plus, RouteCollection is the routing rule specified throughout the current Application. Custom controls Microsoft offers a htmlhelper that is already available to most developers, but some of the features that Microsoft provides htmlhelper may not be sufficient. next, Let's talk about how to customize the Process. The first way to customize is to extend the HtmlHelper Object. Three elements of the extension method implementation: 1, static class 2, static method 3, This keyword 1, first define a class, for example: myhtmlhelper:using system;using system.collections.generic;using System.linq;using system.web;namespace mvcapplicationfirstdome.models {//static classes public static class Myhtmlhelper{//static method} }2, assuming that the way to expand is getspan, the roleThat is, when you pass in the parameter, the inner package returns the result, and the code is as Follows. Note the using SYSTEM.WEB.MVC namespace is to be referenced in the Myhtmlhelper class. static method public static string Getspan (this htmlhelper htmlhelper,string text) {return "<span style= ' color:red ' >" + text+ "</span>";} After two steps above the HtmlHelper extension method Getspan Basic can be used, then explain how to call on the Page. Notice the next namespace when calling: if the namespace of the extension method and the Page's namespace are different, you must refer to the namespace of the extension method, otherwise there is no way to invoke the custom method on the Page. Once you have referenced the namespace, you can invoke the custom extension method on the appropriate Page. Custom controls are too complex and time-consuming for some projects. You can also download MVC controls that suit your needs from the technical community or source code station at this Time. such as some control packages, table controls, and so On. [14]  </dd> </dl><p><p> Introduction to the MVC framework </p> </p></span>

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.