免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1283 | 回复: 0
打印 上一主题 下一主题

smarty和html_QuikForm联合编程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-30 01:27 |只看该作者 |倒序浏览
折腾一个下午,把smarty和html_QuikForm联结到一起了
源码:
test.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联合编程实验');      $form->addElement('text', 'txtFirstName', '贵姓?');      $form->addElement('text', 'txtLastName', '尊名?');      $form->addElement('text', 'txtAge', '年龄?');      $form->addElement('text', 'txtTelephone', '电话?');      $form->addElement('reset', 'btnClear', '复位');      $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
/usr/share/php/smarty');
require(myinclude.'/libs/Smarty.class.php');
//setup.php是一个很好的加载应用程序的类库文件(就是扩展类)
//例如你可以在index文件里包含它
class Smarty_my extends Smarty {
   function Smarty_my() {
  
           // Class Constructor. These automatically get set with each new instance.
//类构造函数.创建实例的时候自动配置
        $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
 
 
 
 
 
 
    {$form_data.header.hdrTesting}
 
 
   
   
     
        {$form_data.txtFirstName.label}
        {$form_data.txtFirstName.html}
        {$form_data.txtLastName.label}
        {$form_data.txtLastName.html}
     
     
        {$form_data.txtAge.label}
        {$form_data.txtAge.html}
        {$form_data.txtTelephone.label}
        {$form_data.txtTelephone.html}
     
     
     
       
          {$form_data.btnClear.html} {$form_data.btnSubmit.html}
       
     
     
     
       
          ©2005 陈刚 实验
       
     
   
层叠式样表文件my.css
body {
    background-color: #10F2E7;
}
 table {margin:1px;} 
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;
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8235/showart_38347.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP