smarty模板引擎(三)配置文件数据和保留数据

来源:互联网 发布:淘宝如何代理虚拟 编辑:程序博客网 时间:2024/06/05 04:02
一、如何让模板直接从配置文件中取出数据
1.使用场合
    当某个变量值,不希望直接写死到程序中(通过smarty分配),就可以通过配置文件来获取。
2.写配置文件
    新建文件夹:config
    新建文件名:my.ini或my.config
    内容:key=value;
    例子:
    title="This isthe 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}>
















0 0
原创粉丝点击