RE: Favortire Page template Structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Exactly.  I have really loved doing sites this way.  One caveat though.
Unless you buffer the entire page you must send headers before the
template file is included.

<?
if (something) {
	header("Location: somewhere.php4");
	exit();
}

function output() {
}
include "template.php4";
?>


This is because the template will echo to the browser before the output
function is called.  So if the output function is going to redirect the
client to another page, you must do the redirect before the page is
sent.  Then the other thing I have done is define variables outside the
function or multiple functions for things like the title of the page,
maybe meta data, or a function to generate a menu on the template.  Then
to take this a little further you could store the template html in a
database and allow a user to select which template they would like to
see when they log into the site.  And if you break it up still further
you could define sections on the template that could be stored in a DB
so the user could select which sections they see and possibly organize
the layout as they see fit.

Charles Killmer
Netgain Technology
Open Source Rocks!

 

-----Original Message-----
From: Jim MacDiarmid [mailto:jim.macdiarmid@xxxxxxxxxxx] 
Sent: Wednesday, March 24, 2004 9:38 AM
To: Charles P. Killmer
Subject: RE:  Favortire Page template Structure

So in your Output function you would have just tables?  No
<HTML><HEAD><BODY></BODY></HEAD</HTML> stuff?

I'm finding that there are not many examples for layout like this or
other ways. 

Thanks for sharing!  :)

Jim

-----Original Message-----
From: Charles P. Killmer [mailto:charlesk@xxxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, March 24, 2004 9:53 AM
To: php-windows@xxxxxxxxxxxxx
Subject: RE:  Favortire Page template Structure


I have been very fond of this method that I developed over the last few
years.

Lets say you have a site with three pages.  Index, about us, and contact
us.

I create index.php like this
<?
function output() {
?>
	html stuff here
<?
}
include "template.php";
?> 

About us and contact us look the same

Template then just has 



<?
	session starting
	any security stuff here
?>
HTML Stuff
<?
output();
?>
More html




Then changing the look of the site is just in that one file.  And things
like webtrends still give accurate results.

Charles Killmer
Netgain Technology









-----Original Message-----
From: Jim MacDiarmid [mailto:jim.macdiarmid@xxxxxxxxxxx] 
Sent: Wednesday, March 24, 2004 8:36 AM
To: php-windows@xxxxxxxxxxxxx
Subject:  Favortire Page template Structure

I was interested in seeing if anyone has a favorite way of structuring
their PHP pages? For instance, I found one example where pages were laid
out as follows:

Everything was based off of index.php and parameters were submitted
through the hidden fields or through an action variable on the url
querystring.

Index.php
--------- Begin example index.php ---------- <?php
/*
 * Common include files here
 * Database connection initialization includes here
 * Security includes here
 */


/*
 * define local functions here
 */


/*
 * Initialize globals variables 
 * and constants here 
 */


/*
 * Define a main function here
 */

Function main(){

/*
 * Initialize local variables 
 * and constants here 
 */

  /* capture action variable on url querystring */	  	

  /* do something based on action */	
  
}
?>

/* HTML Code here */


-----8<-- End Example --->8--

Any thoughts on this? I'm still kinda new at PHP and wanted to learn the
best way to structure my code from the git-go.  :)

Thanks in advance,
Jim

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux