includes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

includes

Post by rsmarsha »

I work on a website which uses an index template with a content area. A content file holds a list of variables like:

if ($page=home) include 'home.php';

then home would be pulled into the index content area.

The other way would be having a header,footer and nav bar, pulled into each page, which would be the best? Does the first way make the site any slower? As if not it's much easier to keep it that way than change all the files.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

includeing a page like that is very common and it wont slow anything down
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

I usually have a function named getContent() for static pages or getScript() for dynamic ones written on those includes. This I can include its contents to my HTML string.

Code: Select all

include "includes/nav_functions.php"
// ...
include "contents/home.php"
$bodystr = "
<body>
<table>
<tr><td>".getNavMenu()."</td></tr>
<tr><td>".getContent()."</td></tr>
</table>
</body>";
// ...
echo $headstr.$bodystr;
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks for the replies.

I'll stick to the content file with the page includes in. Would it be better to use a switch block for the $page variable? I know switch will break when it finds a match.

Just wondering as the content gets fairly large after a lot of pages are added. :)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

switch or a bunch of if's
it's your preference

If the coding is quite lengthy switch may be best
Post Reply