Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 9th, 2002, 07:42 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Article Discussion: Implementing a Template Based Web Site With PHP

Implementing a Template Based Web Site With PHP Need help with this article or have your own outtake on a PHP template based website? Please post your comments/questions under this thread.

You can read the article here .

Reply With Quote
  #2  
Old April 9th, 2002, 08:10 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Just a quick question about the actuall template,
(im going to use an example here)

say this is my template

<html>
<head>
<title>$title</title>
</head>
<body>
$content<br>
Todays Date: $date
</body>
</html>

now that would work, but what about this.

<html>
<head>
<title>$title</title>
</head>
<body>
$content<br>
Todays Date:
<?php
echo gmdate("d-m-Y");
?>
</body>
</html>

Would that work/is their any way to make it run any php inside the template?? I know this defeats the point of a template (seperating the php from the html) but it saves me declairing the date on every page

Thanks

Reply With Quote
  #3  
Old April 10th, 2002, 08:00 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
if you used the eval() function then yes, it would.

Reply With Quote
  #4  
Old April 13th, 2002, 08:49 AM
billsanders billsanders is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Oklahoma, USA
Posts: 13 billsanders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to billsanders
PHP templates for web pages

I developed my own template-based PHP/MySQL default web site. Anyone is welcome to use it if they like. Be sure to read all the comments so you can follow my logic.

I use three files: "page.inc", "baseCalendar.inc" and "template.php".

I cannot attach the files since they are not valid file types for attachment, so I enclose them in their entirety in the main body of this post.

Here is page.inc:

<?php
// page.inc
// to create a new page, use template.php

class Page {

// default properties for all class members
var $title = "PHP Page";
var $host = "phpHost";
var $user = "phpUser";
var $pwd = "phpPwd";
var $db = "phpDb";
var $MYSQL_ERRNO = '';
var $MYSQL_ERROR = '';

// constructor function (to create a Page object)
function Page($newTitle=false, $newHost=false, $newUser=false, $newPwd=false, $newDb=false) {
$this->title = ($newTitle) ? $newTitle : $this->title;
$this->host = ($newHost) ? $newHost : $this->host;
$this->user = ($newUser) ? $newUser : $this->user;
$this->pwd = ($newPwd) ? $newPwd : $this->pwd;
$this->db = ($newDb) ? $newDb : $this->db;
}

// default methods
function displayTitle() {echo("<title>" .$this->title. "</title>");}

function displayHead() {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META name="robots" content="noindex, nofollow">
<meta name="keywords" content="noindex, nofollow">
<meta name="description" content="noindex, nofollow">
<META NAME="author" CONTENT="Bill Sanders">
<META NAME="copyright" CONTENT="2002">
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<META HTTP-EQUIV="Window-target" CONTENT="_top">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">

<style type="text/css">
<!--
body { margin:10px; background-color:#F7D79B; color:black;
font:14px/1.2 arial,helvetica,sans-serif }
h2 { background-color:#9D7F46; color:#FFFFC5; padding:5px;
border:1px solid black; margin:0; text-align:center }
h3 { text-align:center }
tr { vertical-align:top }

.indent { margin-left:50px }
.fl { clear:both; float:left; height:1.8em }
.fr { clear:right; float:right; height:1.8em }
.center { text-align:center }
.dark { background-color:#f7c86d }
.light { background-color:#f7e4bf }

.navbar { text-align:right; background-color:#ccaf7d;
font-size:smaller; padding:3px; margin:0;
border-left:1px solid black;
border-bottom:1px solid black }
.navbar a { color:#FFFFC5 }
.navbar a:visited { color:#7D5F26 }

@media print {
body { font:11pt/1.1 'times new roman',times,serif;
margin:0; background-color:white; color:black; }
h2 { background-color:#ccc; color:black; border:1px solid black;
padding:0.3em; text-align:center }
.dark { background-color:#bbb }
.light { background-color:#ddd }
}
-->
</style>

<?php $this->displayTitle(); ?>

<script type="text/javascript">
<!--
// for refresh time in footer and status bar greeting
today = new Date();
hours = today.getHours();
minutes = today.getMinutes();
if (hours<7) greeting = 'Good morning!
(getting an early start?)';
else if (hours<12 && hours>6) greeting = 'Good morning!';
else if (hours<18 && hours>11) greeting = 'Good afternoon!';
else if (hours<21 && hours>17) greeting = 'Good evening!';
else greeting = 'Good evening! (working late?)';
halfDay = (hours>11 && hours<24) ? 'PM' : 'AM';
hour = (hours>12) ? (hours-12) : hours;
minute = (minutes<10) ? ':0' +minutes : ':' +minutes;

timeStr = hour+minute+ ' ' +halfDay;

window.defaultStatus=greeting;
// -->
</script>

<?php
}

function displayFoot(){
?>
<br style="clear:both"><br>
<div style="text-align:right; font-size:x-small">
This page was last modified on our server on
<?php echo date("j M Y",getlastmod()); ?><br>
and last refreshed on our server at
<?php echo date("h:i a, "). " Central Time, " .date("j M Y");
?><br>
<script language="JavaScript" type="text/javascript">
<!--
document.write('Which reads as '+timeStr+ ' on this computer.');
// -->
</script>
</div>
</body>
</html>
<?php
}

function dbConnect() {
$dbConn =
mysql_connect($this->host, $this->user, $this->pwd);
if (!$dbConn) {
$this->MYSQL_ERRNO = mysql_errno();
$this->MYSQL_ERROR = mysql_error();
return false;
} else if ($this->db && !mysql_select_db($this->db,$dbConn)) {
$this->MYSQL_ERRNO = mysql_errno();
$this->MYSQL_ERROR = mysql_error();
return false;
} else return $dbConn;
}

function sql_error() {
if (!$MYSQL_ERROR) {
$this->MYSQL_ERRNO = mysql_errno();
$this->MYSQL_ERROR = mysql_error();
}
return
"error number ".$this->MYSQL_ERRNO.": ".$this->MYSQL_ERROR;
}

// end of Page class
}
?>

Reply With Quote
  #5  
Old April 13th, 2002, 09:13 AM
billsanders billsanders is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Oklahoma, USA
Posts: 13 billsanders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to billsanders
I developed my own template-based PHP/MySQL default web site. Anyone is welcome to use it if they like. Be sure to read all the comments so you can follow my logic.

I use three files: "page.inc", "baseCalendar.inc" and "template.php".

I cannot attach the files since they are not valid file types for attachment, so I enclose them in their entirety in the main body of this post.

Here is baseCalendar.inc:

<?php

class BaseCalendar {

var $numYear = "";
var $textMonth = "";
var $thisMonthTimestamp = "";
var $numMonth = "";
var $nextMonthTimestamp = "";
var $numNextMonth = "";
var $textNextMonth = "";
var $yearNextMonth = "";
var $followingMonthTimestamp = "";
var $numFollowingMonth = "";
var $calWidth = "100px";
var $calBGColor = "#f7e4bf";
var $calTextColor = "#000000";

// constructor function, sets current date as default
function BaseCalendar($YYYY=false, $Mmm=false, $calWid=false, $calBGC=false, $calTC=false) {
$this->numYear = ($YYYY) ? $YYYY : date("Y");
$this->textMonth = ($Mmm) ? $Mmm : date("M");
$this->thisMonthTimestamp =
strtotime("1 $this->textMonth $this->numYear");
$this->numMonth = date("n",$this->thisMonthTimestamp);
$this->nextMonthTimestamp =
strtotime("next month",$this->thisMonthTimestamp);
$this->numNextMonth = date("n",$this->nextMonthTimestamp);
$this->textNextMonth = date("M",$this->nextMonthTimestamp);
$this->yearNextMonth = date("Y",$this->nextMonthTimestamp);
$this->followingMonthTimestamp =
strtotime("+2 month",$this->thisMonthTimestamp);
$this->numFollowingMonth =
date("n",$this->followingMonthTimestamp);
$this->calWidth = ($calWid) ? $calWid : $this->calWidth;
$this->calBGColor = ($calBGC) ? $calBGC : $this->calBGColor;
$this->calTextColor = ($calTC) ? $calTC : $this->calTextColor;

echo("<table padding=0 cellpadding=0
style=\"border:1px solid black; float:right;
background-color:".$this->calBGColor.";
color:".$this->calTextColor."\">\n");
echo("<tr valign=\"top\"><td>");
$this->displayMonth();
echo("</td><td style=\"border-left:1px solid black\">");
$this->displayNextMonth();
echo("</td></tr></table>\n");
}

function displayMonth() {
$daysInMonth = date("t",$this->thisMonthTimestamp);
$dayMonthStarts = date("w",$this->thisMonthTimestamp);
$dayNextMonthStarts = date("w",$this->nextMonthTimestamp);
$today = date("n/j");

echo "<table style=\"padding:0; color:#6D4F16;
font-size:x-small; line-height:1em;
width:".$this->calWidth."\">\n";
echo "<tr>
<th colspan=\"7\"
style=\"text-align:center\">".$this->textMonth."&nbsp;
&nbsp;".$this->numYear."</th></tr>\n";
echo "<tr><th>Su</th><th>Mo</th><th>Tu</th>
<th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>\n";
echo "<tr style=\"text-align:center\">\n";
for ($i=0; $i<$dayMonthStarts; $i++) {
echo "<td>&nbsp;</td>\n";
}
for ($i=1; $i<=$daysInMonth; $i++) {
if ($today==date("n/j",strtotime("$i $this->textMonth $this->numYear"))) {
echo "<td style=\"background-color:#f7c86d;
text-align:center; color:black\">$i</td>";
} else {
echo "<td style=\"text-align:center\">$i</td>\n";
}
if (date("w",strtotime("$i $this->textMonth $this->numYear"))==6 && $i<$daysInMonth) {
echo "</tr><tr style=\"text-align:center\">\n";
} else if (date("w",strtotime("$i $this->textMonth $this->numYear"))==6 && $i==$daysInMonth) {
echo "</tr>\n";
} else if ($i==$daysInMonth) {
for ($h=$dayNextMonthStarts; $h<7; $h++) {
echo "<td>&nbsp;</td>\n";
}
echo "</tr>\n";
}
}
echo "</table>\n";
}

function displayNextMonth() {
$daysInNextMonth = date("t",$this->nextMonthTimestamp);
$dayNextMonthStarts = date("w",$this->nextMonthTimestamp);
$dayFollowingMonthStarts =
date("w",$this->followingMonthTimestamp);

echo "<table style=\"padding:0; color:#6D4F16;
font-size:x-small; line-height:1em;
width:".$this->calWidth."\">\n";
echo "<tr><th colspan=\"7\"
style=\"text-align:center\">".$this->textNextMonth."&nbsp;
&nbsp;".$this->yearNextMonth."</th></tr>\n";
echo "<tr><th>Su</th><th>Mo</th><th>Tu</th>
<th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>\n";
echo "<tr style=\"text-align:center\">\n";
for ($i=0; $i<$dayNextMonthStarts; $i++) {
echo "<td>&nbsp;</td>\n";
}
for ($i=1; $i<=$daysInNextMonth; $i++) {
echo "<td style=\"text-align:center\">$i</td>\n";
if (date("w",strtotime("$i $this->textNextMonth $this->yearNextMonth"))==6 && $i<$daysInNextMonth) {
echo "</tr><tr style=\"text-align:center\">\n";
} else if (date("w",strtotime("$i $this->textNextMonth $this->yearNextMonth"))==6 && $i==$daysInNextMonth) {
echo "</tr>\n";
} else if ($i==$daysInNextMonth) {
for ($h=$dayFollowingMonthStarts; $h<7; $h++) {
echo "<td>&nbsp;</td>\n";
}
echo "</tr>\n";
}
}
echo "</table>\n";
}
}
?>

Reply With Quote
  #6  
Old April 13th, 2002, 09:20 AM
billsanders billsanders is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Oklahoma, USA
Posts: 13 billsanders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to billsanders
I developed my own template-based PHP/MySQL default web site. Anyone is welcome to use it if they like. Be sure to read all the comments so you can follow my logic.

I use three files: "page.inc", "baseCalendar.inc" and "template.php".

I cannot attach the files since they are not valid file types for attachment, so I enclose them in their entirety in the main body of this post.

Here is template.php:

<?php
// The next three lines prevent this page from caching
// header ("Cache-Control: no-cache, must-revalidate");
// header ("Pragma: no-cache");
// header ("Expires: Mon,26 Jul 1997 05:00:00 GMT");

# set error reporting level to fatal only
error_reporting(1);

// Set the default values for this page ONLY if different from page.inc.
// Remember to put strings in quotes!
// change 'Template' to your new title for this page
$newTitle = "Template";
// change 'localhost' to your default host name for this page
$host = ($newHost) ? $newHost : 'localhost';
// change 'Satch' to your default user name for this page
$userID = ($newUser) ? $newUser : 'Satch';
// change '123456' to your default password for this page
$password = ($newPwd) ? $newPwd : '123456';
// change 'SUDSY' to your default database name for this page
$database = ($newDb) ? $newDb : 'SUDSY';
// If a Form on this page is to change any of these values, set
// the form Element name="newDb" or name="newPwd" or
// name="newUser" or name="newHost" respectively.
// For example, <input type="text" name="newUser"
// value="type new user ID here">

// "page.inc" establishes a class for the Page object
require_once("includes/page.inc");
// Instantiate the Page class (create a new Page object)
$thisPage = new Page($newTitle,$host,$userID,$password,$database);

// Display the HTML from the beginning of the document
$thisPage -> displayHead();

?>

<style type="text/css">
<!--
/* Add style rules specific to this page only. */
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
/* Add scripting specific to this page only. */
// -->
</script>
</head>
<body>

<?php
include( 'includes/BaseCalendar.inc' );
$newCals = new BaseCalendar();
?>

<h2>header</h2>
<div class="navbar">
<a href="../main.php">Return to: Main Page</a>&nbsp;&nbsp;
</div>
<br>
<div style="text-align:right">
<i><script language="JavaScript" type="text/javascript">
<!--
document.writeln(greeting);
// -->
</script></i>&nbsp;&nbsp;
</div>
<br style="clear:both"><br>

<!-- content goes here -->

<?php
// Display the HTML from the end of the document
$thisPage -> displayFoot();
?>

Reply With Quote
  #7  
Old April 28th, 2002, 10:07 AM
m0h m0h is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 2 m0h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not working with me!

Here is the code:
PHP Code:
<?
//Conect to the database
include("db.php"); 
dbConnect("test");

function 
gettemplate($templatename

global 
$templatecache

#check if template has already been loaded 
if ($templatecache[$templatename]!="") { 

#return cached version 
$template $templatecache[$templatename]; 

} else { 

#retrieve from database 
$query mysql_query("SELECT content FROM templates WHERE name='$templatename'"); 

if (
mysql_num_rows($queryid)!=0) { 

#get the db field 
$template mysql_result($query,"content"); 

#replace \" with \\" ... this will be needed later in the script 
$template str_replace("\"","\\\"",$template); 

#cache the contents 
$templatecache[$name] = $template

} else { 
$template=""


return 
$template


#set the page title and query 
$pagetitle "Search Results"
$searchquery "Dummy search"

#get the database information 
$query mysql_query("SELECT title,hits FROM items ORDER BY hits DESC LIMIT 10"

#loop through the results 
while ($data=mysql_fetch_array($query)) { 

#load the template for this instance, appending the data onto $resultbits 
eval("\$resultbits .= \"".gettemplate("ResultsBit")."\";"); 



#now return the whole template 
eval("echo \"".gettemplate("ResultsPage")."\";"); 
?>

It gives me:

Parse error: parse error in /home/telefon/public_html/admin/test.php on line 47

I have both tables (items & templates) setup as said in the article

Reply With Quote
  #8  
Old April 28th, 2002, 06:53 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$query = mysql_query("SELECT title,hits FROM items ORDER BY hits DESC LIMIT 10")

whats wrong with this line? your missing the ';'
i make this mistake all the time, it should work now me thinks

Reply With Quote
  #9  
Old April 29th, 2002, 09:29 AM
m0h m0h is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 2 m0h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
oops! How didn't I notice it!
Any way this is how it is in the article, I also noticed anther error in the article, in page 3
Code:
CREATE TABLE items ( 
id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, 
title varchar(30) NOT NULL, 
hits int NOT NULL DEFAULT '',   
); 

There is an extra ",".

Now after I added the missing ";" I'm getting anther error:
-START-

Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/test.php on line 21

Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/test.php on line 21

Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/test.php on line 21

Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/test.php on line 21

-END-

It would be nice if the author of this article check it and fix all the error.

Thanx alot

Reply With Quote
  #10  
Old May 23rd, 2002, 10:30 AM
strangepup's Avatar
strangepup strangepup is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Phoenix, AZ
Posts: 44 strangepup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 46 sec
Reputation Power: 17
Send a message via ICQ to strangepup
Any chance of getting the support material for this article posted? I am kind of lost, but I would probably be okay if I had the files in front of me to examine.

Thanks

Reply With Quote
  #11  
Old August 7th, 2002, 09:13 PM
CoolAsIce CoolAsIce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 3 CoolAsIce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
eval() and functions

i was hoping someone would help me out with this...

i used the article's template design in my pages, and it's working quite well. however, i wanted to include a poll within the template HTML, but the poll code is grabbed as...

display_poll(n), where n is the poll id

when i place $poll in the template and use

$poll = display_poll(n);

and then the eval statement to parse $poll, "display_poll(n);" just comes up as plain text instead of the actual poll HTML. any help on this would be greatly appreciated!

Reply With Quote
  #12  
Old August 23rd, 2002, 11:20 AM
vbweb vbweb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: London, UK
Posts: 4 vbweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi everyone. I've just paid another visit to devArticles and noticed all your comments. The two syntax errors you have pointed out have been corrected on the original article at URL There is also a support file available here.

I'd forgotten that this article had already been published here, so I'll have to send an email of to Mitchell.

m0h: The error 'Warning: Supplied argument is not a valid MySQL result resource' means that for some reason an error has occured on the MySQL statement. I suggest you get the actual error message by doing

echo mysql_error();

and see what's gone wrong.

I hope this helps you all

Cheers,

James
URL

Reply With Quote
  #13  
Old September 20th, 2002, 11:12 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
I get a syntax error on line 13 when I try to execute this script (came from the article). It is labeled with "(13)".

db.php has the connection details for MySQL. It also selects the database:
PHP Code:
<? // dummy.php

require_once("db.php");

#set the page title and query
$pagetitle "Search Results";
$searchquery "Dummy search";

#get the database information
$query mysql_query("SELECT title,hits FROM items ORDER BY hits DESC LIMIT 10")

#loop through the results (line 13 follows)
while ($data=mysql_fetch_array($query)) {

#load the template for this instance, appending the data onto $resultbits
eval("\$resultbits .= \"".gettemplate("ResultsBit")."\";");

}

#now return the whole template
eval("echo \"".gettemplate("ResultsPage")."\";");

?>
__________________
Sincerely,
Corbb O'Connor, Author at DevArticles

Reply With Quote
  #14  
Old September 22nd, 2002, 03:49 AM
vbweb vbweb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: London, UK
Posts: 4 vbweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
you need a ; at the end of the
$query = mysql_query("SELECT title,hits FROM items ORDER BY hits DESC LIMIT 10")

line... this has been fixed on the article @ developer fusion.

Regards,

James

Reply With Quote
  #15  
Old September 22nd, 2002, 03:40 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Hi James,

While reading through this thread, I guess I only read part of it.

Thanks.

-Corbb

Reply With Quote
  #16  
Old October 14th, 2002, 03:22 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
OK, I went to http://www.developerfusion.com/show/1658/ but can't seem to find the support material. Where is it?

Reply With Quote
  #17  
Old October 16th, 2002, 04:12 AM
vbweb vbweb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: London, UK
Posts: 4 vbweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Apologies! I uploaded the file ages ago.... but the system didn't update the page to display the support file :|

You can download it from URL

Regards,

James

Reply With Quote
  #18  
Old October 20th, 2002, 10:04 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Thanks James.

Reply With Quote
  #19  
Old November 15th, 2002, 03:30 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation little problem..

After getting your zipfile and testing it on my server I get following error in template.php, hope someone can help me, as I can not see where the Error should be:

error: parse error in c:\apache\htdocs\tmpltest\template.php on line 12


relevant line is this:

$template = fread($handle,filesize("./templates/".$name);

Thank you: Dussy:confused:

Reply With Quote
  #20  
Old November 15th, 2002, 04:21 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
found the errors

$template = fread($handle,filesize("./templates/".$name);

I added a ")" and it worked, also $name three times found in you example was replaced by my with $templatename

and $queryid was replaced with $query

Than it worked, maybe you want to update your example Zip, to make it work proberly, also the Database should be filled with the template by using the dump,

I made a switch with a variable to change between the two options database and File:

The whole Template.php was changed like this by me:

<?
$type = 1;

switch ($type){
case "1":
function gettemplate($templatename)
{
global $templatecache;
#check template has already been loaded
if ($templatecache[$templatename]!="")
{
# cached version
$template = $templatecache[$templatename];

} else {
#retrieve
$handle = fopen("./templates/".$templatename,"r");
$template = fread($handle,filesize("./templates/".$templatename));
#close
fclose($handle);
$template = str_replace("\"","\\\"",$template);
#cache the contents
$templatecache[$templatename] = $template;
}
return $template;
}
break;
case "2":
// db version

function gettemplate($templatename) {
global $templatecache;
#check if template has already been loaded
if ($templatecache[$templatename]!="")
{
#return cached version
$template = $templatecache[$templatename];

} else {
#retrieve from database
$query = mysql_query("SELECT content FROM templates WHERE name='$templatename'");
if (mysql_num_rows($query)!=0) {
#get the db field
$template = mysql_result($query,"content");
#replace \" with \\" ... this will be needed later in the script
$template = str_replace("\"","\\\"",$template);
#cache the contents
$templatecache[$templatename] = $template;
} else {
$template="";
}
}
return $template;
}
break;
}

?>

Reply With Quote
  #21  
Old November 15th, 2002, 04:25 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink Want to say..

That I liked your Tutorial very much, and it helped me creatly to understand how Template is working, I now need to implement a system wich is giving a nice error message, if the tempolate is not in the Database ore Folder, as the Error from the Engine looks quit uggly if it happens

Thank you for this great tutorial - Im currently working on a german translation for your tuto, as it is so well made for beginners!

Thanks Dussy

Reply With Quote
  #22  
Old November 15th, 2002, 04:49 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
found the errors

$template = fread($handle,filesize("./templates/".$name);

I added a ")" and it worked, also $name three times found in you example was replaced by my with $templatename

and $queryid was replaced with $query

Than it worked, maybe you want to update your example Zip, to make it work proberly, also the Database should be filled with the template by using the dump,

I made a switch with a variable to change between the two options database and File:

The whole Template.php was changed like this by me:

<?
$type = 1;

switch ($type){
case "1":
function gettemplate($templatename)
{
global $templatecache;
#check template has already been loaded
if ($templatecache[$templatename]!="")
{
# cached version
$template = $templatecache[$templatename];

} else {
#retrieve
$handle = fopen("./templates/".$templatename,"r");
$template = fread($handle,filesize("./templates/".$templatename));
#close
fclose($handle);
$template = str_replace("\"","\\\"",$template);
#cache the contents
$templatecache[$templatename] = $template;
}
return $template;
}
break;
case "2":
// db version

function gettemplate($templatename) {
global $templatecache;
#check if template has already been loaded
if ($templatecache[$templatename]!="")
{
#return cached version
$template = $templatecache[$templatename];

} else {
#retrieve from database
$query = mysql_query("SELECT content FROM templates WHERE name='$templatename'");
if (mysql_num_rows($query)!=0) {
#get the db field
$template = mysql_result($query,"content");
#replace \" with \\" ... this will be needed later in the script
$template = str_replace("\"","\\\"",$template);
#cache the contents
$templatecache[$templatename] = $template;
} else {
$template="";
}
}
return $template;
}
break;
}

?>

Reply With Quote
  #23  
Old November 15th, 2002, 05:05 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My testversion

If you would be intrested, in how I have modifyd your example so that it is working at my server, than have a look into it here

http://duswald.de/include.php?path=...oad=go&mirror=1

a zip file to download with the modifyd files and the changed mysql dump

greetz: Dussy

Reply With Quote
  #24  
Old November 15th, 2002, 08:45 AM
dussy dussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Bavaria / Germany
Posts: 6 dussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
question to one of the upper posts about eval

Quote:
Would that work/is their any way to make it run any php inside the template?? I know this defeats the point of a template (seperating the php from the html) but it saves me declairing the date on every page


You wrote, it is possible with eval, but how, if I use it, he is yust showing the sourcecode in the Browser?

Dussy

Last edited by dussy : November 18th, 2002 at 02:22 AM.

Reply With Quote
  #25  
Old May 7th, 2003, 09:45 PM
bve bve is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 bve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
?? caching... where is this supposed to be caching the templates?

The way the code reads it should be somewhere in the filesystem?

or is it in memory?

tia

burke

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: Implementing a Template Based Web Site With PHP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap