Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.