Page 1/3 _ PHP Tutorial-php Tutorial for a new hand-written class that combines smarty

Source: Internet
Author: User
Category 13th page for new handwriting combined with smarty. We sincerely invite you to give more valuable comments on the new hand-written smarty class. this class is written for new users (and for themselves) and used in combination with smarty. it is unfinished, now we have released a new hand-written smarty class. We sincerely invite you to give more valuable comments.


This is a combination of smarty classes written for Beginners (and for their own). It is not complete. the purpose of this code is not to be immediately used by new users, therefore, the annotations are not detailed.
I hope you can give me more comments and try to improve it.
First of all, I wrote this to train myself. although I know there are already many similar classes, I decided to write one,
Therefore, please show your mercy during browsing.

I have also packed and uploaded files. put them below. Please download more files and give more comments. Q me if you have any questions

This class currently includes the following functions (for example, set $ m = new Machine_m ())
[Database]
Currently, MYSQL and ACCESS databases are supported.
For configuration, refer to the config. php file.
Use: $ m-> send_query (SQL statement )//
$ M-> select_query (whether to return resources in an SQL statement. if the default value is false, a two-dimensional array is returned)

[Error handling]
System errors and user errors
System error:
$ This-> sys_err ('configuration error, please check the config configuration file', 'di ');
The first parameter records the error information to/lib/error/system. in err, the second parameter is the processing method (keep or die). If you need to modify the browser prompt, you can also set 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 shut', 'die', $ _ SERVER ['http _ referer']);
The first parameter is the prompt displayed on the browser, the second parameter is the processing method (keep or die), and the third parameter is the jump page. if you need to record the error information, you can also set the fourth parameter to record the error message.
To/lib/error/user. err, it is not saved by default.

The browser prompts that the err_page.htm template file under/lib/error/is called by default. you can also set your own error template file and load it with $ m-> err_page =.

[Static generation]
A static page is automatically generated in just one row. you can set the expiration time of the static page when you jump to the page.
(It is still not completely static, completely complex, and not integrated at present. if you want to implement completely static, you can combine my create_html functions and text operation functions)
Usage:
$ M-> create_html (Template File, static output path, output file name );
Jump:
$ M-> goto_html ();
The output file name is equal to the name of the current php file by default. this parameter is provided to enable static paging.

[Two-dimensional array sorting (recommended)]
The two-dimensional array can be sorted as follows: "sort by field a in ascending order and then by field B in descending order"
Usage:
There is an array like this: $ x = array ('name' => 'machine _ map', 'age' => 23 ), array ('name' => 'Tom ', age => 28 ),...... )
Now we want to sort this array in ascending order by name, and then by age in descending order.
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]
I don't know whether to do well. I first wrote a class and then wrote a function to call it. The purpose is to make it easier to use.
Usage: m_page (number of data entries, current page number, number of lines per page, and number of redirect links displayed)
The function returns an array: array (
'Rows '=> how many lines are displayed on each page,
'Prve' => the previous page number, // The so-called large page, is a jump similar to the last 7 pages, next 7 pages
'Next' => next page number,
'Pages' => Total number of pages,
'Start' => Number of SQL query start Records,
'Count' => Total number of records,
'Link' => link page number. // if there are 13 pages in total and the number of links is 7, and the current page is the second largest, the output array)
'Current _ page' => current page number
);

[Verification form]
Write the form to be verified into the function class in advance. you only need to pass $ _ POST into the function class for identification.
Usage: you can see the function as needed.

[Preventing cross-site attacks]
Write this function into a function.

[Chinese truncation function]
I did not write it. I just modified it.

[Upload files]
M_up_file ($ _ FILES, upload path, file type, size limit)
You can set the upload path as follows: 1: Write the folder path directly, 2: array ('GIF' => 'File/GIF ', 'jpg '=> 'File => jpg'). In this way, the gif file is automatically placed in the file/gif folder, and the jpg file is placed in the file/jpg folder.
File type: write 1: 'jpg ', write 2: array ('jpg', 'jpeg ', 'GIF ')
Returns array ('arr' => array of uploaded files, 'Err _ msg '=> error message during Upload, 'num' => Number of uploaded files)

[Text operations (recommended)]
Suppose there is such a string $ str = "Hello! Phpchina ";
We can modify $ new_str = m_txt_replace ('content', 'Machine _ mar', $ str );
The value of $ new_str is "Hello ". Machine _ horse "
Other functions, such as m_txt_add, m_txt_delete, and m_txt_get, are similar.

Note: This is the modification method after the static page is generated.
Refer to 6to23 and think about why he put so many replies on one post at a high speed.
A: Because its reply is not written into the database, it is directly written into the static file, and then modified using methods similar to above. You can look for his source code.

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.