PHP WeChat public development notes (6)

Source: Internet
Author: User

PHP public development notes (6)
PHP public development notes Series
Date: 2014.9.4


Today, we have improved the search, added the Administrator module, optimized identity authentication, and encapsulated student information management into a class (this is really tiring, the main reason is that there is always a problem with the syntax in database operations, which has always been a small problem)


Feelings:
PHP development is so tired that there is no breakpoint and logs cannot be printed in time (I wrote it using sublime, and then I am tired of debugging the public account ), error messages are often not detected in time, or some problems can be eliminated through breakpoint. But it also shows that I am still too sloppy to write code.

Sort notes:
When I write this note, I am catching up with the function. So I simply remember a few pieces of work at that time. Now the function is almost developed, so I will sort out the previous notes.

As mentioned in note 5, some functions to be implemented on the public platform are classified by type: menus and databases are extracted. The advantage of doing so is that in the future, I will make function adjustments or new features will not affect the existing features, which is conducive to development and maintenance.
As mentioned in note 4, I set up a cloud database on SAE and implemented a simple data retrieval function (in the menu-query menu, reply to the name, or the student ID can get the corresponding information). At the suggestion of the student, the student ID needs to quickly search for information. Therefore, a function called quick search is implemented here: the user can obtain relevant information by replying to the name + phone number, name + home address, name + address. The implementation of this function is also based on database retrieval and keyword monitoring.

I. Improved search

To facilitate maintenance, a student information management class is encapsulated, that is, the database management mentioned above, because I was thinking that there may be more database requirements in the future, and the development and maintenance requirements will be higher in the future. Therefore, the files related to database processing at this stage include:



1. student_info_ SQL .class.php is a layer package for mysql_sae.func.php:

1) provide database operation statements in mysql_sae.func.php. The function accepts related parameters. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140912/2014091209043830.png" alt = "\">


2) then, when I use student_info_ SQL .class.php, pass the corresponding parameters.



In addition, this layer of packaging ensures that I can freely control the information to be displayed, that is, I can display the student information and control the display here. When I need to get a data table such as a keyword, then I only need to create a corresponding PHP file, and then control the format in the file;

Here I will mention the sae_log () function that appears in the previous section. This function is also packaged by searching for a print log obtained from the online information:



The purpose of this packaging is that if I don't need to print the log one day, I just need to comment it out.
The packaged student database management class also provides operations such as search and addition. There is nothing to note here.

2. Then we optimized the data retrieval, that is, we can quickly retrieve information based on the requirements of our students. The key point here is keyword capture, here is the use of string-related processing functions in php:
Strstr () and str_replace () mainly use these two functions. The first function is used to determine whether a specific character in a given string exists, and the second function is used to replace the character.

When a user sends a message, I handle it like this:



Process the three keywords. If the message sent by the user has these three keywords, and then use str_replace to replace the keyword with null, the name is obtained, then there will be corresponding response operations. Check_userinfo is used for user authentication. menu_Distribution_Center is a function encapsulated by the sorting menu function that I mentioned earlier. On the basis of independent encapsulation, I only need to capture keywords and then call the functions of the implemented query menu to quickly implement this function. The function implementation is very simple. The problems encountered at the time were mainly php syntax problems, database Syntax problems, and various pitfalls, which also reflected that I was sometimes confused, code writing is too sloppy. After all, php has never been learned by the system. It directly writes code while learning. Therefore, various problems are inevitable.

2. Add the Administrator Module
What should I do if I need to perform operations such as updating database information without using a computer? I thought of implementing an administrator function. Under identity authentication, You can implement the corresponding function by sending specific commands. The specific idea of implementation is to encapsulate it into a class, a unified entry, and then identity authentication. Therefore, I created a new file called admin_sys.class.php and encapsulated it into a class. With a unified entrance, if I have new requirements, then, I only need to add this class, without affecting other system functions:

1. A unified portal:



2. the authentication function implemented here is similar to the previously implemented user identity authentication. It also uses $ _ SESSION to save information:



First, determine whether the Administrator identity is verified. After verification, the specific operation process is started. The specific operation environment is also operated according to the corresponding instructions. This is not mentioned here. It is very convenient to implement this administrator function. I can easily update user information and add user information.

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.