homepage Welcome to WebmasterWorld Guest from 54.211.230.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP includes -- include the content or the code?
I can't decide which approach makes more sense.
mick shrimpton

10+ Year Member



 
Msg#: 2007 posted 8:31 pm on Nov 5, 2003 (gmt 0)

Please give me your thoughts on the pros and cons of these two approaches. Which would/do you do?

Approach 1 -- Include the Content
E.g. a file named template.php loads content with a variable, template.php?content=thispage

template.php would work like this:

code . . . <include thispage> . . . code

Approach 2 -- Include the Layout
Every page would have its own file, e.g. thispage.php, which would work something like this:

<include top> . . . content here . . . <include bottom>

Which approach is better? Why?

Thanks for your help!

 

mogwai

10+ Year Member



 
Msg#: 2007 posted 11:01 pm on Nov 5, 2003 (gmt 0)

Both approaches effectively do the same thing, ie include data from other files to build a page.

I always opt for whatever requires the least amount of work to achieve :) In this case that would be using one template and grabbing the content from a data source of some description. The main reason being that this removes the content from the presentation and makes re-designs and updates much easier.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2007 posted 11:10 pm on Nov 5, 2003 (gmt 0)

mick, there was recently a discussion similar to this on this thread:
[webmasterworld.com...]

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2007 posted 2:04 am on Nov 6, 2003 (gmt 0)

Welcome to WebmasterWorld mick shrimpton,

I guess everyone is forgetting their manners ;)

coopster linked to a very good thread.

I don't think it is, necessarily, a question of what is better. It depends on what works better for you mostly.

One thing I would say though. I try to keep all query strings out of my urls unless absolutely unavoidable. In your first example I would embed the section or pageid/pagename in the code.

$content=thispage;
include "template.php";

Most often I go with the second option. Include the header, content and then include the footer. I also usually maintain title/meta tags on each page so I can customize them for each one.

shady

10+ Year Member



 
Msg#: 2007 posted 2:15 am on Nov 6, 2003 (gmt 0)

I would always go for "including" anything that is likely to be duplicated across my system.
Header and footer are usually (certainly on my sites) the same throughout, therefore I would always include header.php and footer.php.

This approach makes it very easy to change navigation (add another page to your system for example), or add tracking code to the footer.... many reasons I would take this approach.

Best regards
Shady

mick shrimpton

10+ Year Member



 
Msg#: 2007 posted 4:23 am on Nov 6, 2003 (gmt 0)

Thanks for the welcome and the advice.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved