smarty小记,smarty
smarty小记,smarty
项目中经常用到smarty,但是一直用的就是简单的 assgin display foreach if else 等几个方法。 闲下来又看了一遍smarty。简单的记录下有用的东西。
<br /> <span>smarty 系统保留变量 </span><span>$smarty</span>.<span>get #使用方法 $smarty.get.id 下面的一次类推 </span><span>$smarty</span>.<span>post </span><span>$smarty</span>.<span>session </span><span>$smarty</span>.<span>cookie </span><span>$smarty</span>.server<br /><br /> smarty模板中使用PHP中定义的常量<br /> php 文件中定义 define('HIEGHT', 8846);<br /> 模板文件中使用 $smarty.const.HIEGHT<br /><br /> smarty读取配置文件中的变量<br /> 1 $smarty->config_dir = "./conf"; #设置配置文件的路径<br /> 2 配置文件的书写规则 1)配置文件以.conf 结尾 2)配置文件内的书写规则 key1=val1 key1=val1 <br /> 3 使用:在模板文件的头部 {config_load file='site.conf'} <br /> 4 {$smarty.config.site} 即可获取 // {#site#}也可以读取<br /><br /> smarty缓存设置<br /> $smarty->caching = true; #开启缓存 缓存页面<br /> $smarty->cache_lifetime = 3600; #缓存的时间<br /> $smarty->cache_dir = './cache'; #存放换文件的目录 <br /> $smarty->isCached('news.html') 可以判断是否生成了缓存文件 #smarty3里面这么判断<br /> <br /> #一个页面生成多个缓存文件 例子:一个商品详情的页面 根据商品的ID 展现不同的内容 <br /> $id = empty($_GET['id]) ? 1 : $_GET['id'];<br /> $good_name = 'good_name_' . $id;<br /> $smarty->assign('good_name',$good_name);<br /> $smarty->display('tpm.html',$id); # 这样就会根据id生成不同的页面 。 <br /> 注意: 实际的项目中 这个ID 应该是根据参数算出来的。例如根据page,category等参数计算出来。之前公司的一个项目用到了smarty的缓存,这个id的值就是根据page category md5以后得到的。 ecshop中也是这么做的 不过不是MD5。<br /><br /> #清除缓存<br /> $smarty->clearCache('tmp_name')<br /> $smarty->clearAllCache() <br /> <br /> #设置局部不缓存的方法<br /> 1 在标签中 {$time|date_format:"%Y-%M-%D %H:%M:%S" nocache}<br /> 2 {nocache}{/nocache} 控制局部不缓存<br /> 3 php赋值的时候控制不缓存 assign 的第三个参数 设置为true <br /> 4 smarty中的一个insert方法 不细说 感觉没啥用 (囧)
######个人感觉smarty的缓存意义不太大。因为完全可以用redis MEMCHACHE 代替。当然存在即合理 哈哈 <br /><br /><br /> <br /> #变量调节器 :简单说 修改变量的展示形式的功能 例如:
{$time|date_format:"%Y-%M-%D %H:%M:%S" nocache}<br /><br /> #自己也可以写变量调节器 参照plugin里面的文件写就可以了 ###感觉有用。我们的项目中用到了。具体的使用,回头补上。<br /><br /><br />
smarty获取:
1 download: http://www.smarty.net/download
2 通过composer获取 : composer是个很不错的东西。
<br /><br /> <br />

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



The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

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

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

How to write a simple student performance report generator using Java? Student Performance Report Generator is a tool that helps teachers or educators quickly generate student performance reports. This article will introduce how to use Java to write a simple student performance report generator. First, we need to define the student object and student grade object. The student object contains basic information such as the student's name and student number, while the student score object contains information such as the student's subject scores and average grade. The following is the definition of a simple student object: public

Recommended computers suitable for students majoring in geographic information science 1. Recommendation 2. Students majoring in geographic information science need to process large amounts of geographic data and conduct complex geographic information analysis, so they need a computer with strong performance. A computer with high configuration can provide faster processing speed and larger storage space, and can better meet professional needs. 3. It is recommended to choose a computer equipped with a high-performance processor and large-capacity memory, which can improve the efficiency of data processing and analysis. In addition, choosing a computer with larger storage space and a high-resolution display can better display geographic data and results. In addition, considering that students majoring in geographic information science may need to develop and program geographic information system (GIS) software, choose a computer with better graphics processing support.

How to write a simple online reservation system through PHP. With the popularity of the Internet and users' pursuit of convenience, online reservation systems are becoming more and more popular. Whether it is a restaurant, hospital, beauty salon or other service industry, a simple online reservation system can improve efficiency and provide users with a better service experience. This article will introduce how to use PHP to write a simple online reservation system and provide specific code examples. Create database and tables First, we need to create a database to store reservation information. In MyS

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
