《PHP實戰:php簡單smarty入門程序實例》要點:
本文介紹了PHP實戰:php簡單smarty入門程序實例,希望對您有用。如果有疑問,可以聯系我們。
PHP應用本文實例講述了php簡單smarty入門程序.分享給大家供大家參考.具體如下:
PHP應用首先要有3個文件夾configs、templates、templates_c,在configs文件夾中有一個配置文件:test.conf,代碼:
PHP應用
title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true
PHP應用templates中有模板文件:test.htm:
PHP應用
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, {$Name}</H1>
</body>
</html>
PHP應用php文件代碼:
PHP應用
<?php
require 'libs/Smarty.class.php'; //包含Smarty類庫文件
$smarty = new Smarty; //創建一個新的Smarty對象
$smarty->assign("Name","Simon"); //對模版中的變量賦值
$smarty->display('test.htm'); //顯示頁面
?>
PHP應用運行后顯示的頁面代碼:
PHP應用
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, Simon</H1>
</body>
</html>
PHP應用運行之后,還在templates_c文件夾中生成一個php文件:
PHP應用
<?php
/* Smarty version 2.6.22, created on 2009-03-19 13:20:00
compiled from test.htm */
?>
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, <?php echo $this->_tpl_vars['Name']; ?>
</H1>
</body>
</html>
PHP應用這個文件就是瀏覽所顯示出來的效果.
PHP應用希望本文所述對大家的php程序設計有所贊助.
《PHP實戰:php簡單smarty入門程序實例》是否對您有啟發,歡迎查看更多與《PHP實戰:php簡單smarty入門程序實例》相關教程,學精學透。維易PHP學院為您提供精彩教程。