Deep Understanding: Single entry, MVC, ORM, curd, ActiveRecord concepts _php Tips

Source: Internet
Author: User
Tags html form inheritance web services advantage
MVC

MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. The MVC application is divided into three core parts: the model (M), the View (V), the controller (C), each of which handles its own tasks.

views : Views are the interfaces that users see and interact with. For older Web applications, views are an interface of HTML elements, and in new Web applications, HTML still plays an important role in the view, but some new technologies are emerging, including Adobe Flash and Elephant xhtml,xml/xsl, Some identity languages and Web services, such as WML. How to handle the interface of an application is becoming more and more challenging. One big advantage of MVC is that it can handle many different views for your application. There is actually no real processing happening in the view, whether the data is stored online or an employee list, which, as a view, is just a way of outputting data and allowing the user to manipulate it.

Model : The model represents enterprise data and business rules. In the three parts of MVC, the model has the most processing tasks. For example, it might use a Widget object such as EJBS and ColdFusion components to process the database. The data returned by the model is neutral, that is, the model is independent of the data format, such 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 duplication of the code.

Controller : The controller accepts the user's input and invokes the model and view to fulfill 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 or do anything with it. It simply receives the request and decides which model widget to call to process the request, and then determines which view is used to display the data returned by the model processing.

Now we summarize the process of MVC, first the controller to receive the user's request, and decide which model should be called to process, and then the model with business logic to process the user's request and return data, the last controller in the corresponding view format the model returned data, and presented to the user through the presentation layer.

OOP

Object-oriented programming (objectoriented Programming, OOP, object-oriented programming) is a computer programming architecture. One of the basic tenets of OOP is that a computer program is a combination of a single unit or object that can act as a subroutine. OOP achieves the three main goals of software engineering: reusability, flexibility, and scalability. To achieve the overall operation, each object is able to receive information, process data, and send information to other objects. OOP mainly has the following concepts and components:

Component -a unit of data and functionality that is formed in a running computer program that is a modular and structured base in an OOP computer program.

Abstraction-A program has the ability to ignore certain aspects of the information being processed, that is, the ability to focus on the main aspects of the information.

Encapsulation -also known as information encapsulation: ensuring that components do not change the internal state of other components in unpredictable ways, but only in those components that provide internal state-change methods. Each type of component provides an interface that is associated with other components and provides a way to invoke other components.

Polymorphism-a reference to a component and a class assembly involve many other different types of components, and the result of referencing a component depends on the type of the actual call.

Inheritance -Allows the creation of subclass components based on existing components, which unifies and enhances polymorphism and encapsulation. Typically, a class is used to group components, and a new class can be defined as an extension of an existing class, so that the class can be organized into a tree or mesh structure, which embodies the versatility of the action.

Component based programming has become particularly popular in scripting languages due to reasons such as abstraction, encapsulation, reusability, and ease of use.

ORM

Object-Relational mapping (object/relation Mapping, or ORM) is the result of the development of object-oriented software development methods. The Object-oriented development method is the mainstream development method in the enterprise application development environment, and the relational database is the main data storage system which holds the data permanently in enterprise application environment. object and relational data are two representations of business entities, and business entities are represented as objects in memory, and relational data are represented in the database. There is an association and inheritance relationship between objects in memory, and in a database, relational data cannot directly express Many-to-many associations and inheritance relationships. Therefore, object-relational mapping (ORM) systems generally exist in the form of middleware, which mainly implements the mapping of program objects to relational database data.

Object-oriented is developed from the basic Principles of software engineering (such as coupling, aggregation, encapsulation), and relational database is developed from the mathematical theory, there are significant differences between the two sets of theories. In order to solve this mismatch phenomenon, object-relational mapping technology arises.

Curd

Curd is a database technology acronym, the General Project development of the basic functions of various parameters are curd. It represents create,update, read (read), and delete (delete) operations. curd defines the basic atomic operations that are used to process data. The elevation of curd to a technical challenge is due to the completion of a summary-related activity involving curd operations in multiple database systems, whose performance may vary greatly depending on the data relationship.

Curd does not necessarily use the word create, update, read, and delete methods in specific applications, but they accomplish the same function. For example, thinkphp is a curd operation that uses the Add, save, select, and Delete methods to represent the model.

ActiveRecord

ActiveRecord also belongs to the Orm layer, pioneered by rails, following the standard ORM Model: Table Mapping to records, records mapping to objects, fields mapped to object properties. Consistent with the naming and configuration conventions, can be a large degree of rapid implementation of the model operation, and simple to understand.

The main ideas of ActiveRecord are:

1. Each database table corresponds to the creation of a class, each object instance of the class corresponds to a row of records in the database, and every field in the table has a corresponding field in the class;

2. ActiveRecord is also responsible for the persistence of its own, in ActiveRecord to encapsulate the access to the database, that is curd;

3. ActiveRecord is a domain model that encapsulates some of the business logic;

ActiveRecord comparison applies To:

1. The business logic is relatively simple, when your class basically and the database table one by one corresponds, ActiveRecord is very convenient, that is, your business logic is most of the single table operation;

2. When a cross table operation occurs, a transaction script (Transaction script) is often used to elevate the cross table transaction to the transaction script;

3. ActiveRecord The biggest advantage is simple, intuitive. A class includes data access and business logic. It is more convenient if it is used with code generators;

These advantages make ActiveRecord particularly suitable for rapid web development.

Single Entry

A

Single entry usually refers to a project or application that has a uniform (but not necessarily unique) entry file, meaning that all of the project's functional operations are carried out through this portal file, and often the entry file is executed in the first step. The benefit of a single entry for a

is that the project is overall compared to the specification because the same portal often has the same rules as the different operations. Another aspect is the advantage of a single entrance is more flexible control, because interception is convenient, similar to some rights control, user login aspects of judgment and operation can be unified processing.

or some people will worry that all Web sites are accessed through a portal file, which can cause too much pressure, but this is an alarmist idea.

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.