Home > Article > Backend Development > About the implementation of a community system "sidebar"
I am making a lightweight bbs program based on thinkphp.
Assume that one of the columns in the sidebar of the page is used to display user information, such as: number of posts, number of replies, avatar, user name, virtual wealth value and other information.
Another column is used to display the most popular topics in the community, or community information summary, which are dynamic data taken from the database.
How should I implement this sidebar? Because it is reused a lot and the number of sidebars called by each page is different, some pages only need to output the user information sidebar.
Can anyone provide some ideas and explain how to implement it?
The description may be unclear, so I will add more.
I am making a lightweight bbs program based on thinkphp.
Assume that one of the columns in the sidebar of the page is used to display user information, such as: number of posts, number of replies, avatar, user name, virtual wealth value and other information.
Another column is used to display the most popular topics in the community, or community information summary, which are dynamic data taken from the database.
How should I implement this sidebar? Because it is reused a lot and the number of sidebars called by each page is different, some pages only need to output the user information sidebar.
Can anyone provide some ideas and explain how to implement it?
The description may be unclear, so I will add more.
Extract a page to write the sidebar. The name of the sidebar is written in the backend and passed directly. Then use a loop to read the data in the page template, and then use it on whichever page it is. Proceed include
.
The hottest and summary are used as shared templates respectively
Dynamically loaded during data display
You can use redis to cache all the information you need, and each page needs to be cached separately
You can only cache the data part, if it is combined with It will be more convenient to cache and obtain data together with html
Set up the cache and database data reading rules, and cache time, etc.
Front end: Define a common sidebar page, which is imported by all pages.
Backend: Define a Base class to inherit the controller. All controllers inherit Base. Use Base’s initialize() to control and display the side menu
Is that so?
You can refer to discuz. Take a look at their source code.