config_load总结

来源:互联网 发布:java apt 废弃 编辑:程序博客网 时间:2024/06/08 10:15

今天主要总结了一下config_load的一些属性
     属性类型是否必须缺省值描述filestringYesn/a待包含的配置文件的名称sectionstringNon/a配置文件中待加载部分的名称scopestringnolocal加载数据的作用域,取值必须为local, parent 或 global. local 说明该变量的作用域为当前模板. parent 说明该变量的作用域为当前模板和当前模板的父模板(调用当前模板的模板). global 说明该变量的作用域为所有模板.globalbooleanNoNo说明加载的变量是否全局可见,等同于 scope=parent. 注意: 当指定了 scope 属性时,可以设置该属性,但模板忽略该属性值而以 scope 属性为准。


if.conf

#全局变量
bgcolor = #00ffff
display = true            // 主要起限制作用

[mycolor]
bgcolor = #cccc00


[yourcolor]
bgcolor = #123456

if.html

<body>
<form action="if_else.php" method="post">
<input type="text" name="text" />
<input type="radio" name='dq' value="left" />left
<input type="radio" name='dq' value="right" />right
<input type="radio" name='dq' value="center" />center<br />
<input type="submit" value="提交" />

</form>
</body>

if.php

<?php
       
      include 'libs/Smarty.class.php';
      
     
      $link = mysql_connect('localhost','root','123') or die('数据库连接失败');
      mysql_select_db('ecshop_test',$link);
      mysql_query("set names utf8");

      $sql = mysql_query("select * from brand where id like '".$_POST['text']."'");
      $result = mysql_fetch_row($sql);
      
      
      $smarty = new Smarty();
      $smarty->template_dir="demo/templates";
      $smarty->compile_dir="demo/templates_c"; 
      $smarty->config_dir="demo/config";
      $smarty->left_delimiter="<{";
      $smarty->right_delimiter="}>";
      $smarty->assign('text',$result);
      $smarty->assign('dq',$_POST['dq']);
      $smarty->display('if_else.tpl');


if.tpl

<{config_load file='if.conf' section='mycolor'}>
<!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>if_else</title>
</head>

<body bgcolor=<{ #bgcolor# }>>
<{ if #display# }>        //如果display=true,则执行以下代码
<{ if $dq=='left'}>
<div style=" float:left;"> 
<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div>
<{ elseif $dq=='right'}>
<div style=" float:right;">

<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div>
<{else}>
<center><div>
<table>
<tr>
<{ foreach from=$text item=value }>
<td><{ $value }></td>
<{ /foreach }>
</tr>
</table>
</div></center>
<{/if}>

<{ else }>                       //如果display不等于true ,则执行以下代码
没有显示
<{/if}>
</body>
</html>

原创粉丝点击