prefaceSo far, I have done two or three projects, including education, forums, and CMS, and each project uses the comment function, so I want to take out the comment section separately and make it into a componentized module. It not only saves development work, but also allows you to have a better understanding of the functions of this module. Since I am currently mainly developing with the TP framework, the following examples will be presented in the syntax of the TP framework. But in fact, I personally feel that the core method part is insufficient, and I have not made use of the function of the association model. This is what I will implement in the next update. In the main part, I will mainly tell you about the several modes of comment systems that I have been exposed to so far, analyze their respective advantages and disadvantages, and provide an idea of data table design and data extraction, hoping to be helpful to you. If there is anything inappropriate, everyone is also welcome to correct it.
Comment system
There are three main types of common comment systems: building within a building, streaming mode and citation mode (all of which I have given my own names), and the following focuses on the advantages and disadvantages of these three and how to implement them.
1. Building-in-a-building mode The so-called building within a building model means that each comment occupies the first floor, and all replies to the comment are displayed in the building, such as the comment system of Baidu Tieba and Jianshu.
Advantage:Respond to comments with a focused view that makes it easy to understand the conversation they spark.
Disadvantages:When there is too much content, it needs to be pagination, which is more complicated.
Data sheet design:
- id (self-added primary key)
- target_id (ID of the comment topic, which can be changed to article_id, course_id, etc. as needed)
- parent_id (main comment id)
- reply_uid (Record the user ID of the commented, 0 when replying to the main comment)
- UID (User ID who left the comment)
- content (Comment content)
- Other fields... (Time, status, etc.)
Back-end business logic:
2. Flow mode
The flow mode, as the name suggests, is similar to the flow of information, whether it is a comment or a reply, each message occupies a layer, such as the comment system of the laravel-China community.
Advantage:The logic is simple and easy to implement
Disadvantages:The content of the dialogue cannot be presented centrally, and it is not easy to understand the content of the dialogue.
Data sheet design:
- id (self-added primary key)
- target_id (ID of the comment topic, which can be changed to article_id, course_id, etc. as needed)
- reply_uid (Record the user ID of the commented, 0 when replying to the main comment)
- UID (User ID who left the comment)
- content (Comment content)
- Other fields... (Time, status, etc.)
Back-end business logic
3. Citation mode
Citation mode is similar to streaming mode, except that the content of the reply is published with the quoted content.
Advantage:Understanding which comment the reply is aimed at can help you understand what the conversation is about. It is relatively easy to implement.
Disadvantages:Similar to Stream Mode, it doesn't represent the entire conversation in its entirety. By analyzing the advantages and disadvantages, it can be found that the reference pattern is a compromise between the building within the building and the flow mode.
Data sheet design:
- id (self-added primary key)
- target_id (ID of the comment topic, which can be changed to article_id, course_id, etc. as needed)
- reply_id (comment ID of the commented, main comment is 0)
- UID (User ID who left the comment)
- content (Comment content)
- Other fields... (Time, status, etc.)
Back-end business logic:
To get the list of reviews, you can connect the comment table to get the user information and comments that quote the comments. Then do a simple pagination process.
The above is a preliminary summary of the three comment modes, the style part has not yet been sorted out, and after completing the blog project, the front-end style part will also be added. For the above content, if there are any shortcomings, I hope you will provide guidance.
|