仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2337|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页编程之smarty和html_QuikForm结合编程

[复制链接]
山那边是海 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:57:24 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
小试一下身手,大概是没问题了,那么交给你个任务,做个留言本吧,这和HELLO WORLD有一比啊!^_^,同是新手面临的第一道关。     折腾一个下战书,把smarty和html_QuikForm联合到一同了源码:
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结合编程实行');
      $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
<?php
// load Smarty library
define('myclude',/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
<!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 style="font-size:11px; color: navy; text-align: center" colspan="4">
         
山那边是海 该用户已被删除
沙发
 楼主| 发表于 2015-2-10 01:30:32 | 显示全部楼层
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-14 12:32

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表