smarty成功小案例

来源:互联网 发布:融易汇软件使用说明 编辑:程序博客网 时间:2024/04/29 06:19
 
模板页example3.tpl
<!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>例子3</title>
</head>
<body>
{assign var="UserName" value="大师兄"}
{$CheckName|cat:"李晓军"}
下面这一行将显示3个checkbox:<br>
{html_checkboxes name="CheckBox" options=$CheckName checked=$IsChecked1 output=$CheckName separator="<br/>"}//错误发生在这一句checkbox的值无法显示
{html_radios name="RadioBox" values=$RadioName checked=$IsChecked output=$RadioName separator="<br/>"}
下面显示一个月,日年x选择框:<br>

{html_select_date}
<hr><b>CopyRight(c) by xiaojun , li 2004<b>{mailto address="teacher@163.com" text="联系作者"}
</body>
</html>
php页面 example3.php
<?php
include_once("Smarty.class.php");
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->caching = false;
$smarty->debugging=true;
$smarty=new Smarty();
$smarty->assign('CheckName',array(1001=>'语文',1002=>'数学',1003=>'外语'));
$smarty->assign('IsChecked1', '1001');
$smarty->assign('RadioName',array(1001=>'语文',1002=>'数学',1003=>'外语'));
$smarty->assign('IsChecked','语文');
$smarty->assign('$uname',zhenhua);
$smarty->display('example3.tpl');
?>

着重说两重不同的方法,都可以实现。
{html_checkboxes name="CheckBox" options=$CheckName checked=$IsChecked1 output=$CheckName separator="<br/>"}
{html_radios name="RadioBox" values=$RadioName checked=$IsChecked output=$RadioName separator="<br/>"}