折騰一個(gè)下午,把smarty和html_quikform聯(lián)結(jié)到一起了源碼:
test.php
<?php
require_once "html/quickform.php";
require_once 'html/quickform/renderer/arraysmarty.php';
require_once 'link/myload.php';
$form = new html_quickform('frmtest', 'get');
$form->addelement('header', 'hdrtesting', 'smarty&html/quickform聯(lián)合編程實(shí)驗(yàn)');
$form->addelement('text', 'txtfirstname', '貴姓?');
$form->addelement('text', 'txtlastname', '尊名?');
$form->addelement('text', 'txtage', '年齡?');
$form->addelement('text', 'txttelephone', '電話(huà)?');
$form->addelement('reset', 'btnclear', '復(fù)位');
$form->addelement('submit', 'btnsubmit', '提交');
if ($form->validate()) {
# if the form validates then freeze the data
$form->freeze();
}
// create the template object
$tpl =$smarty=& new smarty_my;
$tpl->compile_check = true;
// create the renderer object
$renderer =& new html_quickform_renderer_arraysmarty($tpl);
// build the html for the form
$form->accept($renderer);
// assign array with form data
$tpl->assign('form_data', $renderer->toarray());
// parse and display the template
$tpl->display('my.tpl');
?>
mylink.php
<?php
// load smarty library
define('myclude',/usr/share/php/smarty');
require(myinclude.'/libs/smarty.class.php');
//setup.php是一個(gè)很好的加載應(yīng)用程序的類(lèi)庫(kù)文件(就是擴(kuò)展類(lèi))
//例如你可以在index文件里包含它
class smarty_my extends smarty {
function smarty_my() {
// class constructor. these automatically get set with each new instance.
//類(lèi)構(gòu)造函數(shù).創(chuàng)建實(shí)例的時(shí)候自動(dòng)配置
$this->smarty();
$this->template_dir = '/var/www/apache2-default/smarty/xsgl/templates/';
$this->compile_dir = '/var/www/apache2-default/smarty/xsgl/templates_c/';
$this->config_dir = '/var/www/apache2-default/smarty/xsgl/configs/';
$this->cache_dir = '/var/www/apache2-default/smarty/xsgl/cache/';
$this->caching = true;
$this->assign('app_name','xsgl');
}
}
模板文件my.tpl
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<!-- $id: smarty-guide.tpl,v 1.1 2005/03/03 19:26:54 kae exp $ -->
<head>
<link rel="stylesheet" type="text/css" href="css/my.css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
</head>
<body>
<h2>
</h2>
<form >
<!-- display the fields -->
<table>
<tr>
<th></th>
<td></td>
<th></th>
<td></td>
</tr>
<tr>
<th></th>
<td></td>
<th></th>
<td></td>
</tr>
<!-- display the buttons -->
<tr>
<td align="center" colspan="4">
</td>
</tr>
<!-- display the copyright -->
<tr>
<td colspan="4">
©2005 陳剛 實(shí)驗(yàn)
</td>
</tr>
</table>
層疊式樣表文件my.css
body {
background-color: #10f2e7;
}
table
n {
font-size: small;
font-family: arial, helvetica, sans-serif;
}
table {
overflow: scroll;
margin: 0.1px;
font-weight: lighter;
font-family: arial, helvetica, sans-serif;
}
新聞熱點(diǎn)
疑難解答