Viewed   118 times

I'm looking for advice on the best practice for separating site content up into logical blocks. I want a header and footer that are constant throughout the site, so that if I have several pages of different content, they will all look as below — changes made to the header and footer then update automatically without me having to change each individual page.

<?php
include 'header.php';
?>
<body>
    <p>page content here</p>
</body>
<?
include 'footer.php';
?>

The header.php would contain the opening <html>, <head> and static content, and the footer.php would contain any extra static content and the closing </html> tag. So, my question is: Is this a good approach? I'm worried that spreading the <html> tags across multiple files is bad practice. If so, what is the right way to approach this kind of design?

 Answers

2

Nope, your approach is wrong.
Here are main faults in your design:

  1. You're assuming that header.php would be called on the every page call. That's wrong.
  2. You're assuming that header.php will always be static. That's wrong.
  3. You forgot to create a template for the page itself.

The main rule everyone have to learn by heart:

Not a single character has to be sent into browser, until all data gets ready.

Why?

  • it's 2011 today. AJAX era. What if your code will have to send JSONed data instead of whole HTML page?
  • there is a thing called HTTP header. Sometimes we have to send them. And it's gets impossible if you already have your ornate HTML header sent.
  • it's for just 4-page site. Okay. Imagine you've got lucky and got a request for another 4-page site. You will have to change only templates and don't touch engine files. That's really great benefit.
  • Imagine you're going to make a custom <title> tag for your pages, based on the page content. Isn't it extremely common thing? But you can't make it without using templates.

So, you have to have one common site template containing header and footer and also dedicated templates for the every php script.

An example layout is going to be like this:

.1. page itself.

it outputs nothing but only gather required data and calls a template:

<?php
//include our settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA=dbgetarr("SELECT * FROM links");
$pagetitle = "Links to friend sites";
//etc
//and then call a template:
$tpl = "links.tpl.php";
include "template.php";
?>

.2. template.php which is your main site template,

consists of your header and footer:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My site. <?=$pagetitle?></title>
</head>
<body>
<div id="page">
<?php include $tpl ?>
</div>
</body>
</html>

.3. and finally links.tpl.php is the actual page template:

<h2><?=$pagetitle?></h2>
<ul>
<?php foreach($DATA as $row): ?>
<li><a href="<?=$row['link']?>" target="_blank"><?=$row['name']?></a></li>
<?php endforeach ?>
<ul>

easy, clean and maintainable.

Saturday, December 24, 2022
 
1
  1. First of all, check, are you which is theme layout using in your store? Go to Admin > System > Settings > Edit your store > Store Tab > & then check, you are which template selected here. (default or any other template..)

  2. Go to your site source > catalog > view > theme > default(the previously selected template) > stylesheet > & then you can modify stylesheet.css file. (you will changes in stylesheet.css files according to default OpenCart theme. but, if you have used any other custom template. so You will need to check & find right CSS file.)

Wednesday, November 2, 2022
 
yuk
 
yuk
3

I'm actually about to release one at europaphp.org along with examples and a full documentation. It's very similar to the Zend Framework in conventions and coding standards. I'll post something when it is done; probably within the next week.

You can get the code at: [http://code.google.com/p/europa/source/browse/#svn/trunk/Sandbox - Default][1].

That link will bring up the latest svn for the Sandbox which you can just download and start using without any configuration.

Currently, it's faster than most any other PHP framework out there.

[1]: http://code.google.com/p/europa/source/browse/#svn/trunk/Sandbox - Default

Tuesday, December 27, 2022
 
3

I found this topic here

Someone sais:

I've had this problem before. Make sure you upload your file in ASCII not Binary. Sometimes, with some FTP servers, you have to set this manually. Also try converting your newlines to "n" in your text editor. Lemme know which editor you're using and I'll give you more specific instructions.

http://forums.digitalpoint.com/showthread.php?t=957679

And someone solved it : I solve this problem using notepad++ (http://notepad-plus.sourceforge.net/) Open php files with notepad++ and in Format menu chose encode in utf-8 without BOM and save it.

Hope this helps to

Tuesday, August 30, 2022
 
4

Look at your php.ini and make sure allow_url_include is set to 1. Restart HTTPD, done.

Monday, December 19, 2022
 
plato
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :