Home  >  Article  >  php教程  >  smarty模板引擎之配置文件数据和保留数据,smarty模板

smarty模板引擎之配置文件数据和保留数据,smarty模板

WBOY
WBOYOriginal
2016-06-13 09:08:42886browse

smarty模板引擎之配置文件数据和保留数据,smarty模板

本文实例讲述了smarty模板引擎之配置文件数据和保留数据的方法。分享给大家供大家参考。具体如下:

一、如何让模板直接从配置文件中取出数据

1.使用场合

当某个变量值,不希望直接写死到程序中(通过smarty分配),就可以通过配置文件来获取。

2.写配置文件

新建文件夹:config
新建文件名:my.ini或my.config
内容:key=value;

例子:

title="This is the title of the website."
bgcolor="pink"

3.使用方法

载入配置文件:{config_laod file="路径"}
使用配置文件数据:

例子:

{config_laod file="my.config"}
<body bgcolor='<{#bgcolor#}>'>...</body>

二、如何获得保留变量的数据

即,如何取得get/post/session/server数据。这些数据是保存在数组中的,smarty封装了方法,可以直接通过smarty变量进行获取。

1.获得get数据

传统方式:先取得get数据,再分配给smarty。但是smarty本身封装了方法,不用分配,就可以直接获得get数据。

使用方法如下:

用户名:<{$smarty.get.username}><br/>
密码:<{$smarty.get.password}><br/>

2.获得post数据

使用方法如下:

用户名:<{$smarty.post.username}><br/>
密码:<{$smarty. post.password}><br/>

3.获得server数据

使用方法如下:

服务器名称:<{$smarty.server.SERVER_NAME}>

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn