- 论坛徽章:
- 0
|
SimpleT 的作者原来就是 Harry Fuecks
再来一个。也是Harry Fuecks的
- <?php
- /* index.php */
- /* Include fictional data access class */
- include("classes/Dao.php");
- /* Connect to database */
- $dao=new Dao ("dbhost","dbname","dbuser","dbpass" );
- /* Include awesome template engine */
- include("classes/AwesomeTemplateEngine.class.php");
- /* Fire up template engine */
- $path = "/home/user/www/templates/";
- $awesomeTemplateEngine= new AwesomeTemplateEngine($path);
- $dataObject=$dao->;fetchObject("SELECT name, email, signature FROM users ORDER BY name");
- $awesomeTemplateEngine->;parseTemplate($dataObject,"viewuser_template.php");
- ?>;
复制代码
- <?php
- /* viewuser_template.php */
- ?>;
- <html>;
- <head>;
- <title>;View User</title>;
- </head>;
- <body>;
- <?php
- foreach ($dataObject as $dataChild) {
- ?>;
- <p>;Name:<?php echo ($dataChild->;name); ?>;
- <p>;Email:<?php echo ($dataChild->;email); ?>;
- <p>;Signature:<?php echo ($dataChild->;name); ?>;
- <?php
- }
- ?>;
- </body>;
- </html>;
复制代码
And the Awesome Template engine...
PHP:
- <?php
- /* AwesomeTemplateEngine.class.php */
- class AwesomeTemplateEngine {
- var $templatePath;
- function AwesomeTemplateEngine($templatePath) {
- $this->;templatePath=$templatePath;
- }
- function parseTemplate($dataObject,$template) {
- include($this->;templatePath.$template);
- }
- }
- ?>;
复制代码 |
|