Home >Backend Development >PHP Tutorial >PHP WeChat Public Development Notes (6)_PHP Tutorial

PHP WeChat Public Development Notes (6)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:03919browse

PHP WeChat Public Development Notes (6)

PHP WeChat public development notes series
Date: 2014.9.4


Today we mainly improved the search, added the administrator module, optimized the identity authentication, and encapsulated the student information management into a class. Question)


Feeling:
It’s really tiring to develop PHP without breakpoints and not being able to print logs in time (I wrote it in sublime, and then debugged it directly on the WeChat official account, which made me tired). Error messages are often not detected in time, or some problems can be solved through breakpoints. It was ruled out but could not be ruled out. But it also shows that I am still too sloppy when writing code.

2014.9.10 Organizing notes:
When I wrote this note, I was working on a feature, so I simply jotted down a few notes about my work at that time. Now that the feature is almost developed, I’m going to sort out the previous notes.

In Note 5, I mentioned that some functions that need to be implemented on the public platform have been classified by type: menus and databases have been extracted. The advantage of this is that if I make functional adjustments or add new functions in the future, it will not affect the existing functions, which is conducive to development and maintenance.
In Note 4, I mentioned that I built a cloud database on SAE and made a simple data retrieval function (reply the name or student number in the menu-query menu to get the corresponding relevant information). Under the suggestion, we need to find information quickly, so a function I call quick retrieval is implemented here: users can get the corresponding relevant information by replying name + phone number, name + hometown, name + address; the implementation of this function is also established Based on database search and keyword monitoring.

1. Improve search

For the convenience of maintenance, a student information management class is encapsulated here, which is a package for the database management mentioned before, because I thought at that time that there might be more database requirements and later development. Maintenance requirements will be higher; therefore, the relevant files processed by the database at this stage are:



1. student_info_sql.class.php is a layer of packaging for mysql_sae.func.php:

1) Provide statements for database operations in mysql_sae.func.php, and the function accepts relevant parameters 喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20140912/2014091209043830.png " alt="">


2) Then when I use student_info_sql.class.php, I can pass the corresponding parameters



And such a layer of packaging can ensure that I can freely control the information that needs to be displayed. That is, when I display student information, I can control the display here. When I need to create a data table such as keywords, then I only need to create a new corresponding php file, and then control the format in the file;

Here I would like to mention the sae_log() function that appears in the above picture. This function is also packaged as a printed log obtained by searching for information on the Internet:



The purpose of my packaging is that if one day I don't need to print the log, I can just comment it out here.
The packaged student database management class also provides operations such as retrieval, addition, etc. There’s nothing here that requires additional notes.

2. Then there is the optimization of data retrieval mentioned, which means that information can be retrieved quickly according to the needs put forward by students. The key point here is to capture keywords, and here is the use of string-related processing in PHP. Function usage:
strstr(), str_replace() I mainly use these two; the first function is used to determine whether a specific character appears in a given string, and the second function is used to replace characters.

When the user sends a message, I do this:



Process these three keywords. If the message sent by the user contains these three keywords, then use str_replace to replace the keywords with empty words to get the name, and then there will be corresponding response operations. The check_userinfo that appears in the picture above is what I use for user authentication; menu_Distribution_Center is a function encapsulated by the menu organizing function I mentioned before, menu distribution. On the basis of independent encapsulation, I only need to capture keywords, and then call the related functions of the implemented query menu to quickly implement this function. The function implementation is very simple. The problems encountered at that time were mainly PHP syntax problems, database syntax problems, and various pitfalls. It also reflected that I am sometimes too careless and careless when writing code, and there is PHP after all. I have not learned it systematically, I just learned it while writing code, so it is inevitable that I will encounter various problems.

2. Add the administrator module
Because sometimes the computer is not used, and at this time, operations such as updating database information are needed. What should I do? I thought of implementing an administrator function. Under the condition of identity verification, the corresponding function can be implemented by sending specific instructions. The specific idea of ​​​​my implementation is to encapsulate it into a class, a unified entrance, and then authenticate. Therefore, I created a new file called admin_sys.class.php and encapsulated it into a class. After having a unified entrance, if I have new needs in the future, then I only need to add it to this class. , will not affect other system functions:

1. A unified entrance:



2. The verification function implemented here is similar to the user identity verification implemented before, and $_SESSION is also used to save information:



First determine whether the administrator's identity has been verified. After verification, enter the specific operation link. The specific operating environment is also operated according to the corresponding instructions. I won’t mention it here. It is very convenient to implement this administrator function. I can easily update user information, add user information, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/879183.htmlTechArticlePHP WeChat Public Development Notes (6) PHP WeChat Public Development Notes Series Date: 2014.9.4 Today is mainly improved Search, added administrator module, optimized identity verification, student information...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn