Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 09:08:31
Original
922 people have browsed it

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

 这篇文章主要介绍了smarty模板引擎之配置文件数据和保留数据的方法,实例分析了smarty模板引擎配置文件数据及获取数据的具体技巧,具有一定参考借鉴价值,需要的朋友可以参考下

 

 

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

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

1.使用场合

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

2.写配置文件

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

例子:

?

1

2

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

bgcolor="pink"

3.使用方法

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

例子:

?

1

2

{config_laod file="my.config"}

...

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

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

1.获得get数据

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

使用方法如下:

?

1

2

用户名:

密码:

2.获得post数据

使用方法如下:

?

1

2

用户名:

密码:

3.获得server数据

使用方法如下:

?

1

服务器名称:

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

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!