ThinkPHP3.0 _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
ThinkPHP3.0. I am very excited to see the new version of ThinkPHP3.0, because it has put forward many new concepts, such as the CBD model and AOP programming ideas. Summarize these two new concepts. The new version of ThinkPHP3.0 was introduced by the official operator in the CBD. it was very excited because it proposed many new concepts, such as the CBD model and the AOP programming idea. Summarize these two new concepts.

CBD knowledge

Reference the official manual: ThinkPHP3.0 introduces a brand new CBD (Core + Behavior + Driver) architecture model, because from the underlying layer, the framework adopts a core + behavior +-driven architecture system. The core retains the most critical part, and tags are set to mark important points, other functions are combined with behavior extensions and drivers. developers can expand or replace the behavior of a tag location based on their own needs to easily customize the underlying framework, you can also add your own tag location and application line at the application layer. The label position is similar to the "aspect" in the AOP concept. the behavior is to program the "aspect". if the built-in core extension of the system is regarded as a standard mode, users can customize all these behaviors into a new mode. Therefore, in ThinkPHP, it is called pattern extension. In fact, pattern extension can not only replace and increase behavior, you can also replace and modify the underlying MVC to achieve the purpose of customization. With this new feature, developers can easily customize a development framework of their own or enterprise through mode extension. The new version of mode extension is a collection of Framework extensions, it has created a new milestone, which is the true charm of the new version.

Awareness of AOP

Reference the official manual:

AOP (Aspect-Oriented Programming) can be said to be a supplement and improvement of OOP (Object-Oriented Programing, object-oriented Programming. OOP introduces concepts such as encapsulation, inheritance, and polymorphism to establish an object hierarchy to simulate a set of public behaviors. When we need to introduce public behavior to scattered objects, OOP seems powerless. That is to say, OOP allows you to define the relationship from top to bottom, but it is not suitable for defining the relationship from left to right. For example, log function. Log code is often horizontally distributed across all object layers, but it has nothing to do with the core functions of the objects it spreads. This is also true for other types of code, such as security, exception handling, and transparent persistence. This unrelated code distributed everywhere is called cross-cutting code. in OOP design, it leads to a large number of code duplication, which is not conducive to the reuse of each module. The AOP technology is the opposite. it uses a technology called "cross-cutting" to segment the encapsulated object, encapsulate the public behaviors that affect multiple classes into a reusable module and name it "Aspect", that is, Aspect. The so-called "aspect" is simply to encapsulate the logic or responsibilities that are irrelevant to the business but are called by the business module to reduce repeated system code, reduce the coupling between modules and facilitate future operability and maintainability. AOP represents a horizontal relationship. if "object" is a hollow cylinder that encapsulates the attributes and behaviors of objects, then the method for aspect-oriented programming is, it is like a sharp blade that splits these hollow cylinders to obtain internal messages. The cut section is the so-called "aspect. Then it restored these cut sections with the skill of winning the power of Heaven without leaving any trace.

Using the "cross-cutting" technology, AOP divides the software system into two parts: the core focus and the cross-cutting focus. The main process of business processing is the core focus, and the part that has little to do with it is the cross-cutting focus. One feature of cross-cutting concerns is that they often occur in multiple places of core concerns, and are similar everywhere. For example, permission authentication, logs, and transaction processing. The function of Aop is to separate the various concerns in the system from the core concerns and the cross-cutting concerns. As Adam Magee, Avanade's senior solution architect, said, the core idea of AOP is to "separate the business logic in applications from the general services it supports ."



My personal understanding: AOP is a programming idea. it is to make some functional modules that need to be reused in the entire project one by one, so that we will not write code repeatedly in this project. While the CBD is the implementation method of the AOP idea, and some functions that need to be used more (that is, the so-called aspect) are written into one Behavior, so that we only need to use this Behavior, this Behavior has only one method for calling, that is, run. other Behavior behaviors are private attributes. In addition, this call method is encapsulated into the B ($ name, & $ param) method. when we call the aspect behavior, we only need to execute the B method. (This form conforms to the dependency injection idea. the advantage is to implement code decoupling ).

So, if ThinkPHP2.X is used, how can we better use these good programming ideas without changing the framework. Before creating a project, you must first make overall planning for the project, such as repeated behaviors, such as project-level special verification of data, we can make it into a Behavior so that we only need to reuse this section.

After reading ThinkPHP3.0, I personally think that 3.0 and 2.x are not much different. However, 3.0 emphasizes that we should make overall planning prior to the project and use the AOP idea to avoid repeated code. Take advantage of the nutrients and use them in programming.

Bytes. Summarize these two new concepts. CBD recognition reference official hand...

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.