您的位置:首页 > 其它

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>

    

      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  config file