Sam Granger Posted October 23, 2007 Share Posted October 23, 2007 Hello guys! I am trying to integrate a template system into my already existing system. Please take a look at my code below: <?php /** * @author Sam Granger * @copyright 2007 */ defined('parent') or die('Direct access to this file is not allowed!'); $interface = new Interface('array'); $interface->title = "News"; $interface->keywords = "News"; $database = new MySQL(); $connection = $database->Connect($DB_SERVER, $DB_USER, $DB_PWD, $DB_NAME); $sql = "SELECT id, title, DATE_FORMAT(published,'%d-%m-%Y') AS published FROM news"; $query = $database->Query($sql); while($array = $database->FetchArray($query)){ extract($array); echo "<p>$id, $title, $published</p>"; } $interface->content = "Stuff should really go here!"; $interface->Display(); ?> If you can take a look at the while statement, you can see it outputs all rows from the news table. I want "$interface->content" to get all these values. How do I achieve this? Here's my template class: <?php defined('parent') or die('Direct access to this file is not allowed!'); class Interface{ var $content = ""; var $title = ""; var $keywords = ""; var $description = ""; var $layout = ""; var $stylesheet = ""; var $body = ""; function Interface($pagetype){ $this->stylesheet = "style.css"; $this->body = "Start<contentarea />End"; } function DisplayHead(){ echo '<title>'; echo $this->title; echo '</title>'; echo ''; echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'; echo ''; echo '<meta name="DESCRIPTION" content="'; echo $this->description; echo '" />'; echo ''; echo '<meta name="KEYWORDS" content="'; echo $this->keywords; echo '" />'; echo ''; echo '<link rel="stylesheet" href="'; echo $this->stylesheet; echo '" type="text/css" />'; } function DisplayBody(){ echo str_replace("<contentarea />", $this->content, $this->body); } function Display(){ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en-us"> <head>'; $this->DisplayHead(); echo '</head> <body>'; $this->DisplayBody(); echo '</body> </html>'; } } ?> Thanks for looking! Link to comment https://forums.phpfreaks.com/topic/74489-solved-problem-templating-something/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.