smarty和html

來源:互聯網
上載者:User

  折騰一個下午,把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">
          ©2005 陳剛 實驗
        </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;
}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.