专为新手写的结合smarty的类第1/3页
专为新手写的结合smarty的类,诚挚邀请大家多提宝贵意见
这个是为新手(也为自己)写的结合smarty一起使用的类,是未完成的,现在放出来的目的不是马上让新手使用,所以也没有把注解写的非常详细
希望各位高手多多提意见,我尽量完善它。
首先声明,我写这个的目的也是为了锻炼自己,尽管我知道现在已经有很多类似的类了,但是我还是决定来写一个,
所以请大家在浏览的时候口下留情。
还有文件我也已经打包上传了,放在下面,请大家多多下载,多多提意见。有什么问题直接Q我
目前该类包括以下功能(使用范例,设$m = new Machine_m())
[数据库]
目前支持MYSQL与ACCESS两种数据库
配置参考config.php文件
使用:$m->send_query(SQL语句)//
$m->select_query(SQL语句,是否返回资源,默认为false即返回一个二维数组)
[错误处理]
分为系统错误和用户错误
系统错误:
$this->sys_err( '配置错误,请检查config配置文件', 'die');
第一个参数将记录错误信息到/lib/error/system.err中,第二个参数是处理方法(keep or die),如果需要修改浏览器端提示的话,还可以设置第三个参数,它默认为“很抱歉,本站发生系统错误,请稍候再试。”
用户错误:
$m->user_err( '注册系统关闭', 'die', $_SERVER['HTTP_REFERER'] );
第一个参数是显示到浏览器端的提示,第二个参数是处理方法(keep or die),第三个参数是跳转页面,如果需要记录错误信息的话,还可以设置第四个参数,它将记录错误信息
到/lib/error/user.err中,不设默认不保存。
浏览器端的错误提示默认调用/lib/error/下的err_page.htm模版文件,也可以设置自己的错误模版文件,然后用$m->err_page=加载。
[静态生成]
只用短短一行就自动生成静态页面,跳转时可设置静态页面过期时间
(现在还是不完全的静态,完全的比较复杂,目前没有整合,大家如果要实现完全静态的话,可以结合我的create_html函数和文本操作系列函数实现)
使用方法:
$m->create_html(模版文件,静态输出路径,输出的文件名);
跳转:
$m->goto_html();
输出文件名默认等于当前php文件的文件名,提供这个参数目的是,当有需要使用静态分页时,可以用这个参数设置
[二维数组排序 (推荐)]
可以让二维数组作类似:“先按字段a升序,再按字段b降序”这样的排序
使用方法:
设有这样一个数组:$x = array( array('name'=>'machine_马', 'age'=>23),array('name'=>'tom',age=>28),…… )
我们现在要把此此数组先按name升序排,再按age降序排
则用法为m_sort($x,'name',SORT_ASC,'age',SORT_DESC)
[动态加载]
对于不常用的功能,我采用加载的方法来使用,个人认为这样可以节约资源
例如,如果我们要使用m_sort函数时,默认是没有加载这个函数的
需要这样加载:$m->load_func('m_sort')
然后就可以使用m_sort函数了
[分页]
这里我也不知道做得好不好,我是先写了一个类,再写一个函数来调它,目的是使用得时候比较方便
使用方法:m_page(数据条数,当前页号,每页多少行,显示多少个跳转链接)
函数返回一个数组:array(
'rows' => 每页显示多少行,
'prve' => 上一大页页号,//所谓大页,就是类似上7页,下7页这样的跳转
'next' => 下一大页页号,
'pages' => 共有多少页,
'start' => SQL查询的开始记录数,
'count' => 共有多少条记录,
'links' => 链接页号,//如果共有13页,链接数是7个,当前又在第二大页,则输出array(8,9,10,11,12,13)
'current_page' => 当前页号
);
[验证表单]
把需要验证的表单事先写进函数类,判别的时候只需要把$_POST传入就可以了
使用方法:这个大家自己看函数就应该看得明白,这个函数需要大家按照自己的需求来修改的
[防止跨站攻击]
把这个功能也写道一个函数内了
[中文截取函数]
不是我写的,拿来修改了一下而已
[上传文件]
m_up_file($_FILES,上传路径,文件类型,大小限制)
其中上传路径可以这样设置,1:直接写文件夹路径,2:array('gif'=>'file/gif','jpg'=>'file=>jpg'),这样gif文件自动放入file/gif文件夹,jpg文件放入file/jpg文件夹
文件类型:写法1:'jpg',写法2:array('jpg','jpeg','gif')
返回array( 'arr' => 已上传的文件数组, 'err_msg' => 上传过程中的错误信息, 'num' => 上传成功数 )
[文本操作 (推荐)]
假设有这样一个字符串 $str="你好phpchina";
我们可以这样修改 $new_str=m_txt_replace('content','machine_马',$str);
现在$new_str的值为"你好machine_马"
其他的几个函数,如:m_txt_add,m_txt_delete,m_txt_get都是类似的,大家可以自行参看。
注意:这个就是生成静态页面之后,修改的方法。
可以参见6to23并思考为什么他一篇帖子放了那么多回帖速度还那么快
答:因为它的回帖没有进数据库而是直接写到静态文件里面,再使用类似我上面的方法来修改的。你可以看他的源代码,找找

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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.
