Smarty的配置文件
2012-11-08 22:07
183 查看
一、$smarty的配置文件
1、在模板中如何加载呢?
通过<{config_load file="**配置文件的名称**" section=“**配置文件中的局部选择**”}>//这是在模板中加载的部分
2.在php文件中通过:$smarty->config_dir="**配置文件的路径(不需要文件的名称)"//这里边也许有我总结错的不过我全都是经过实践的哦 《如果有错请你们纠正哦!!》
举个小例子:这是配置文件中的bgcolor变换背景颜色
******这是tpl的模板文件***********
<{config_load file='config.conf'}>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body bgcolor="<{#bgcolor#}>">
<{if $dq=='left'}>
<div style=" float:left;"><{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div>
<{elseif $dq=='right'}><div style="float:right;"><{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div>
<{else}><center><div>
<{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div></center>
<{/if}></body>
</html>
*********这是php加载模板的文件**************
<?php
include 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->template_dir="demo/templates";//设置模版目录
$smarty->compile_dir="demo/templates_c";//设置编译目录
//***********************************
//设置定界符
//*************************
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
//*****************************
这是链接数据库的代码
//****************************
$ql=mysql_connect('localhost','root','');
$qw="set names utf8";
mysql_query($qw);
mysql_select_db('xsxx',$ql);
$re="select * from stu where id like '".$_POST['text']."'";
$result=mysql_query($re);
$row=mysql_fetch_assoc($result);
//把数据库的文件根据表单的提交 根据id查询出整条数据
$smarty->config_dir="demo/config";//加载配置文件
$smarty->assign("text",$row);
$smarty->assign('dq',$_POST['dqfs']);
$smarty->display("if_smarty_form.tpl");
?>
*****************以下是html的表单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="if_smarty.php" method="post">
请输入学号:
<input type="text" name="text" />
<input type="radio" value="left" name="dqfs" />left
<input type="radio" value="center" name="dqfs" />center
<input type="radio" value="right" name="dqfs" />right
<input type="submit" value="提交" />
</form>
</body>
</html>
1、在模板中如何加载呢?
通过<{config_load file="**配置文件的名称**" section=“**配置文件中的局部选择**”}>//这是在模板中加载的部分
2.在php文件中通过:$smarty->config_dir="**配置文件的路径(不需要文件的名称)"//这里边也许有我总结错的不过我全都是经过实践的哦 《如果有错请你们纠正哦!!》
举个小例子:这是配置文件中的bgcolor变换背景颜色
******这是tpl的模板文件***********
<{config_load file='config.conf'}>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body bgcolor="<{#bgcolor#}>">
<{if $dq=='left'}>
<div style=" float:left;"><{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div>
<{elseif $dq=='right'}><div style="float:right;"><{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div>
<{else}><center><div>
<{foreach from=$text item=value}>
<{$value}>
<{/foreach}></div></center>
<{/if}></body>
</html>
*********这是php加载模板的文件**************
<?php
include 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->template_dir="demo/templates";//设置模版目录
$smarty->compile_dir="demo/templates_c";//设置编译目录
//***********************************
//设置定界符
//*************************
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
//*****************************
这是链接数据库的代码
//****************************
$ql=mysql_connect('localhost','root','');
$qw="set names utf8";
mysql_query($qw);
mysql_select_db('xsxx',$ql);
$re="select * from stu where id like '".$_POST['text']."'";
$result=mysql_query($re);
$row=mysql_fetch_assoc($result);
//把数据库的文件根据表单的提交 根据id查询出整条数据
$smarty->config_dir="demo/config";//加载配置文件
$smarty->assign("text",$row);
$smarty->assign('dq',$_POST['dqfs']);
$smarty->display("if_smarty_form.tpl");
?>
*****************以下是html的表单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="if_smarty.php" method="post">
请输入学号:
<input type="text" name="text" />
<input type="radio" value="left" name="dqfs" />left
<input type="radio" value="center" name="dqfs" />center
<input type="radio" value="right" name="dqfs" />right
<input type="submit" value="提交" />
</form>
</body>
</html>
相关文章推荐
- smarty的有关配置文件
- 用smarty配置文件改变页面的风格
- 从配置文件读取smarty变量
- 为smarty模版创建配置文件
- smarty 的模版配置文件的使用
- 编写smarty配置文件
- 关于Smarty的配置文件
- smarty保留变量与调用配置文件
- smarty初始配置,文件存放路径
- 一、SMARTY安装于配置文件
- PHP模板引擎Smarty之配置文件在模板变量中的使用方法示例
- smarty 从配置文件读取变量 config_load
- smarty6(加载配置文件)
- smarty中加载配置文件和运用循环
- Smarty入门教程二-----使用配置文件避免每次都配置路径
- Smarty配置文件!
- smarty的配置文件以及配置文件的加载
- Smarty 配置文件的读取
- smarty配置文件
- PHP 中使用 Smarty 之二:配置文件在模板变量中的使用