In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use weiphp to achieve the message board, the article is very detailed, has a certain reference value, interested friends must read it!
1. Functional analysis
The traditional message board should have the functions of posting messages, checking messages, replying to messages, managing messages and so on. This tutorial develops the most basic message board, which only contains two functions: publishing messages and viewing messages. According to the function, the foreground page style made with bootstrap is as follows:
2. Create a new weiphp plug-in
In the first step, we designed the foreground effect page according to the functional requirements of the message board, then the next step is to gradually develop the weiphp plug-in according to the effect.
The first step is to create a plug-in in the weiphp background management page. Remember to select "Yes" for both the configuration item and the management list.
The second step is to install the created plug-in and click the installation link on the right side of the plug-in
Go back to the weiphp front desk management page and click on the message board on the left to see the installed message board plug-in.
3. View the code structure
After the plug-in is created successfully, the weiphp framework automatically generates a plug-in folder in the Addons directory. This tutorial generates a liuyanban folder, and the liuyanban directory includes three folders: Controller, Model and View, and two files: config.php and LiuyanbanAddon.class.php. Controller generally writes logic processing code, including data insertion, data query and other function code, Model mainly writes some code that interacts with Wechat, and View puts foreground template inside. Config.php is the configuration file, and LiuyanbanAddon.class.php is the plug-in information file, which generally does not need to be modified.
4. Test whether the plug-in is available
Open Model/WexinAddonModel.class.php
Add test code. The simplest test code is $this- > replyTest ('hello world')
The following figure shows lines 13 and 14 of the test code. When users reply to "message board" in Wechat, they will return the system time and prompt message.
Test whether the plug-in is available in Wechat
Bingo, the plug-in is available normally. Let's move on.
5. Create a configuration file
Open config.php and write the configuration code shown in the following figure
If you reopen the message board management interface, you can see that the configuration item has been set successfully
Open Model/WexinAddonModel.class.php, re-edit the Wechat response code (lines 15-25), and return the picture and text message.
Re-test the message board plug-in in Wechat
Return to the single Teletext message, bingo, keep going.
6. Import the foreground template
First, download the foreground template. The foreground page I saw at the beginning has been uploaded to my Baidu network disk, which can be downloaded here: http://www.php.cn/
Second, upload the downloaded foreground template to the View/default/Liuyanban folder
Write the code of the output foreground in Controller/LiuyanbanController.class.php
Click the picture and text message replied in Wechat, you can go to the front desk home page.
The home page you see now is just a static html page. Click publish > > without any jump. We need to add a jump link to publish > >.
Open the index.html page, and on line 22, change the href link to "publish > >" as shown in the following figure, that is, jump to the liuyan () method under the current controller, and pass the token and uid parameters. BTW: {: U ('','')} template method for generating url for thinphp. If you don't understand, please make your own Baidu.
Earlier, when we wrote LiuyanController, we wrote a liuyan () method, which did not do any logical processing, but just displayed the message page, that is, jump to liuyan.html. After changing the link address of href, click "publish > >" in the upper right corner of index.html to jump to the message publishing page shown in the following figure.
Similarly, the "View > >" link in the upper right corner of the post message cannot be redirected. On line 19, we change the href to the figure below.
7. Analysis and creation of data model
Database design is undoubtedly the top priority in IT technology. Please learn about the database by yourself in Baidu mysql course. Weiphp provides a convenient web management data table model. For the foreground page we saw at the beginning, let's take a look at the input fields in the posting message page.
According to the analysis, this message board plug-in only needs two visible fields: message name (name) and message content (content). At the same time, there should be message time (cTime), official account Token (token), and user UID (uid). Knowing this, we began to design the database model.
Open the weiphp background management page, and create a new liuyanban data model. The model shown in the screenshot below is identified as liuyan_info. It is recommended that you change it to liuyanban, because only when the data model is named liuyanban (consistent with the plug-in name), the default weiphp foreground message board management list can display data. How to change the default data display page and create several different data models are not within the scope of this tutorial. So let's write the data model logo in the following figure as liuyanban.
After creating the data model, we start to create the required fields for the message board plug-in, and click Field Management-> New Field on the right side of the data model operation interface. Create the five fields mentioned above: token, uid, cTime, name and content. Add the field completion rule in the Advanced option of the field creation page, add get_token () for token, add get_mid () for uid, and add time () for cTime.
This is all the fields we need for the message board plug-in we created.
Go back to the model management page, click Edit on the right side of the liuyanban model, and change the list definition of the liuyanban model to the following figure, so that the front management page of the message board can display the data.
When you go back to the front desk management page of the message board, you can see the fields and actions that display the data (message holder, message content, message time, operation)
At this point, the whole database design process is complete, and the next step is to establish logic to process the code to manipulate the data.
8. Query user information
Open Controller/LiuyanbanController.class.php, write the code lines 16, 17 and 18 shown in the following figure in the liuyan () method, and query the user's information according to the user's uid, and output the information to the message name filling box on the message posting page. The purpose of this is to facilitate the operation of the user. As long as the personal information has been bound once, there is no need to repeat the name when leaving a message.
On the liuyan.html page, change the value of the input box of the name to the user's name, and {$user.nickname} is the nickname of the output user
When entering the posting message page, as long as we have previously bound personal information, the bound nickname can be automatically displayed in the message name input box.
9. Insert message data
Write the data processing code in the liuyan () method (lines 21-34). When the user submits the message data, the message data is inserted into the liuyanban data table.
After inserting a few test data into the message page, you can go back to the message board plug-in management page and see the message data submitted by the user.
10. Display message information
Create a new data query code in the index () method to extract the data from the liuyanban data table and display it to the index.html foreground template
In index.html, use thinkphp template tags to circulate the message data output. BTW:weiphp is developed based on thinkphp, and all thinkphp tags are available in weiphp, so the key to learning weiphp plug-in development is to understand basic thinkphp knowledge.
Open index.html and you can see all the message data.
At this point, the entire weiphp message board plug-in development is complete, to see the effect of this plug-in, please reply in the "Idou Wonderland" Wechat public platform in the "message board", as for the later how to package and download the plug-in, upload it to the new weiphp framework or export the data model, please check the official weiphp documentation.
The above is all the contents of the article "how to use weiphp to implement the message board". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.