


Classes combined with smarty specially written for novices Page 1/3_PHP Tutorial
A class specially written for novices to be used in conjunction with smarty. We sincerely invite everyone to provide valuable feedback
This is a class written for novices (and for myself) to be used in conjunction with smarty. It is unfinished Yes, the purpose of releasing it now is not to let novices use it immediately, so I haven’t written the annotations in very detail
I hope you experts can give me your opinions and I will try my best to improve it.
First of all, let me state that the purpose of writing this is to train myself. Although I know that there are many similar classes now, I still decided to write one.
So please be gentle when browsing.
I have also packaged and uploaded the files and put them below. Please download them and give your comments. If you have any questions, please ask me directly
Currently, this class includes the following functions (use example, assuming $m = new Machine_m())
[Database]
Currently supports MYSQL and ACCESS databases
Configuration refers to the config.php file
Use: $m->send_query (SQL statement) //
$m->select_query (SQL statement, whether to return resources, the default is false, which returns a two-dimensional array )
[Error handling]
Divided into system errors and user errors
System error:
$this->sys_err( 'Configuration error, please check the config configuration file', 'die ');
The first parameter will record the error information to /lib/error/system.err. The second parameter is the processing method (keep or die). If you need to modify the browser prompt, you can also set it. The third parameter, which defaults to "Sorry, a system error occurred on this site, please try again later."
User error:
$m->user_err( 'Registration system is closed', 'die' , $_SERVER['HTTP_REFERER'] );
The first parameter is the prompt displayed on the browser, the second parameter is the processing method (keep or die), the third parameter is the jump page, if you need to record If there is an error message, you can also set the fourth parameter, which will record the error message
to /lib/error/user.err. If it is not set, it will not be saved by default.
The error prompt on the browser side calls the err_page.htm template file under /lib/error/ by default. You can also set your own error template file and then load it with $m->err_page=.
[Static generation]
Automatically generate a static page with just one line, and you can set the static page expiration time when jumping
(It is still not completely static, and it is more complicated at present. There is no integration. If you want to achieve complete static, you can combine my create_html function and text operation series functions to achieve it)
Usage:
$m->create_html (template file, static output path, output file name);
Jump:
$m->goto_html();
The output file name defaults to the file name of the current php file. The purpose of providing this parameter is to use static paging when it is necessary. You can use this parameter setting
[Two-dimensional array sorting (recommended)]
to sort the two-dimensional array like: "First ascending order by field a, then descending order by field b"
Usage:
Set an array like this: $x = array( array('name'=>'machine_马', 'age'=>23),array('name'=>'tom ',age=>28),... )
We now need to sort this array in ascending order by name, and then in descending order by age
The usage is m_sort($x,'name',SORT_ASC, 'age',SORT_DESC)
[Dynamic loading]
For infrequently used functions, I use the loading method. I personally think this can save resources
For example, if we want to use the m_sort function This function is not loaded by default
You need to load it like this: $m->load_func('m_sort')
Then you can use the m_sort function
[Paging]
Here I don’t know if I did it well or not. I first wrote a class and then a function to adjust it. The purpose is to make it more convenient to use
Usage method: m_page (number of data items, current page number, each page How many rows, how many jump links to display)
The function returns an array: array(
'rows' => How many rows to display on each page,
'prve' => The page number of the previous page ,//The so-called large page is a jump like the previous 7 pages and the next 7 pages
'next' => The page number of the next large page,
'pages' => How many pages are there in total,
'start' => Number of starting records of SQL query,
'count' => How many records are there,
'links' => Link page number, //If there are 13 pages in total, link The number is 7, and it is currently on the second largest page, then output array(8,9,10,11,12,13)
'current_page' => current page number
);
[Verification Form]
Write the form that needs to be verified into the function class in advance. When judging, you only need to pass in $_POST.
Usage method: You should be able to understand this by looking at the function. This function needs to be modified according to your own needs
[Prevent cross-site attacks]
This function is also written in a function
[Chinese interception function]
It was not written by me, I just modified it
[Upload file]
m_up_file($_FILES, upload path, file type, size limit)
The upload path can be set like this, 1: Write the folder path directly, 2:array('gif'=>'file/gif','jpg'=>'file=>jpg'), so that the gif file is automatically placed in the file/gif folder, jpg Put the file into the file/jpg folder
File type: Writing method 1:'jpg', Writing method 2:array('jpg','jpeg','gif')
Return array( 'arr' => Array of uploaded files, 'err_msg' => Error message during upload, 'num' => Number of successful uploads)
[Text operation (recommended)]
Suppose there is such a character String $str="Hellophpchina";
We can modify it like this $new_str=m_txt_replace('content','machine_马',$str);
Now the value of $new_str is "Hellomachine_马"
Several others Functions such as: m_txt_add, m_txt_delete, m_txt_get are similar, you can refer to them yourself.
Note: This is how to modify the static page after generating it.
You can refer to 6to23 and think about why he posted so many replies in one post and it is so fast
Answer: Because its replies are not entered into the database but written directly into the static file, and then use a method similar to mine above to modify. You can look at his source code and look for

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Mistlock Kingdom is an open world game where players can play as Sons of Fire to survive and explore. The game combines the unique entertainment of action RPG challenges, bringing players endless surprises and joy. In the game, players can explore resources, environments, weapons and more. Some novice players may be curious about how to get started with the game. In this introduction and sharing, we will provide you with some relevant getting started guides. Tips for Beginners to the Fog Lock Kingdom: The danger levels of areas shrouded by miasma are different. During the exploration process, new areas of the map will be gradually unlocked, and the location of the areas shrouded by miasma can be seen. The map will be distinguished by two colors. The blue area can be entered in a short time. The time you can stay will also be different depending on the character's ability level.

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

Anchor Arrival is a 3D turn-based card game with a high-definition beautiful girl two-dimensional theme. It provides a rich and exciting combination of characters for players to explore and experience. It has many powerful combinations of high-quality lineups. New players are also curious novices. What powerful characters are recommended in the pool? Let’s take a look at the selection reference for novices to win ten consecutive golds! Anchor Point Advent is a powerful character recommendation for novice pools. The first ten-consecutive pick is Alice. She is mainly a single-target lightning-type burst character. The output is very explosive, and the experience will be very friendly to newcomers, so it is highly recommended to choose it. It is recommended to choose the combination of "Alice" + "Antelope" for 10 points. Alice is the most worthy character to output the goldpire attribute, and is not even a bit stronger than the other two characters in the novice card pool. Alice can pass special

Essential skills for newbies to PyCharm: Mastering the use of batch indentation requires specific code examples Overview: PyCharm is a powerful Python integrated development environment (IDE) that provides many practical tools and functions to help developers improve efficiency . In the daily coding process, we often need to indent the code to keep the code format neat and beautiful. The batch indentation function provided by PyCharm can help us quickly batch indent the code and improve coding efficiency. This article will explore Py

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing

Crown of the Ancients is a high-quality and strategic card mobile game based on Western magical adventure. In-game secret exploration, ruins adventure, national championship and other special gameplay are waiting for you to experience. So for novice players, if they want to get started with this game quickly, a novice guide is indispensable. Today, the editor will bring you the relevant guide, let’s take a look. An overview of the Ancient Crown beginner’s guide, gameplay and area opening styles: 1. Diamond accumulation flow: Everything is focused on accumulating diamonds, and then you start to work hard after leaving the village. Except for the main magic weapon, three flywheel activities, etc., which require diamonds, the others are ignored. The main focus is on one of them. Don't pay attention to the hero challenge. You can fight as many as you can, and don't force it. Advantages: You only need to mess around to accumulate diamonds. After leaving the village, you can quickly access the latest activities with diamonds, get new series of hardware heroes, and diamonds are broken.
