Newbie: Organising a website using PHP 
Author Message
 Newbie: Organising a website using PHP

As a web designer I am making the transition from designer to developer and
am studying PHP and MySQL at present with apache setup locally for testing
purposes.

Before when I have designed a website I often used Dreamweaver templates to
organise my site making site wide updates quite fast.

I am starting to learn the basics of PHP in terms of syntax, functions and
classes but wanted more information in terms of the organisation of a site
using PHP.

Using PHP to build a small web site would the best approach be to have one
file containing the 'template' code (eg common.php)and each page calling
functions from the common file to build the layout. Eg the common file
contains a function which writes the navigation bar for a page. And content
specific to the individual page is laid out between these functions?

Or do programmers tend to put the layout code straight into a database with
the code being called from there?

Can anyone point me to a diagram or page or something which shows how
developers might organise a site and how each newly created page would be
created.



Mon, 30 May 2005 18:39:37 GMT  
 Newbie: Organising a website using PHP

Quote:
> Using PHP to build a small web site would the best approach be to have one
> file containing the 'template' code (eg common.php)and each page calling
> functions from the common file to build the layout. Eg the common file
> contains a function which writes the navigation bar for a page. And
content
> specific to the individual page is laid out between these functions?

You can use some template engine like: Fasttemplate, Smarty, TemplateTamer
or some other. Those engines will let you sparate html and logic.

rush
--
http://www.templatetamer.org/



Mon, 30 May 2005 18:57:10 GMT  
 Newbie: Organising a website using PHP
k thanks..that looks like one way of doing it

but how would a developer approach a small php website without the use of a
3rd party app like templatetamer...

I think what I am looking for is reassurance that the approach i suggested
(eg one common file containiing the general page layout written in functions
or classes and called from the individual pages) is a typical approach to
organising a site. I did read somewhere that the truely dymanic sites call
everything from the database.

further info would be appreciated.


Quote:


> > Using PHP to build a small web site would the best approach be to have
one
> > file containing the 'template' code (eg common.php)and each page calling
> > functions from the common file to build the layout. Eg the common file
> > contains a function which writes the navigation bar for a page. And
> content
> > specific to the individual page is laid out between these functions?

> You can use some template engine like: Fasttemplate, Smarty, TemplateTamer
> or some other. Those engines will let you sparate html and logic.

> rush
> --
> http://www.templatetamer.org/



Mon, 30 May 2005 19:14:33 GMT  
 Newbie: Organising a website using PHP

Quote:
> k thanks..that looks like one way of doing it

> but how would a developer approach a small php website without the use of
a
> 3rd party app like templatetamer...

You could put common elements in separate php file, and then include them in
each page where you need them. For instance you can have menu bar in one
separate php file, and then include this php on each page where you would
like to have this menu. It is workable,and many sites especially older ones
are built that way, but it gets more and more messy as your site grows, gets
more complicated, or both.

rush
--
http://www.templatetamer.org/



Mon, 30 May 2005 19:45:36 GMT  
 Newbie: Organising a website using PHP
Quote:
>It is workable,and many sites especially older ones
> are built that way, but it gets more and more messy as your site grows,
gets
> more complicated, or both.

If this is the case which approach do the more modern larger sites take?

Quote:



> > k thanks..that looks like one way of doing it

> > but how would a developer approach a small php website without the use
of
> a
> > 3rd party app like templatetamer...

> You could put common elements in separate php file, and then include them
in
> each page where you need them. For instance you can have menu bar in one
> separate php file, and then include this php on each page where you would
> like to have this menu.
> rush
> --
> http://www.templatetamer.org/



Mon, 30 May 2005 20:02:05 GMT  
 Newbie: Organising a website using PHP

Quote:
> >It is workable,and many sites especially older ones
> > are built that way, but it gets more and more messy as your site grows,
> gets
> > more complicated, or both.

> If this is the case which approach do the more modern larger sites take?

Well, you can do it as descibed, and I am afraid that if I answer this
question you are going to conclude that I am using hard selling practices on
you :).

Also I would not like to start the religious war about this since one thing
can be accomplished in many ways, and different people have different
approaches. But many bigger or complex sites do use some sort of templating,
and if your site is going to grow, I would recommend you to use some sort of
templates.

rush
--
http://www.templatetamer.org/



Mon, 30 May 2005 20:33:21 GMT  
 Newbie: Organising a website using PHP


But many bigger or complex sites do use some sort of templating,

Quote:
>and if your site is going to grow, I would recommend you to use some sort of
>templates.

Do you know of good articles about how to go doing this? I'm currently
looking at PHP templating systems along with Zope, and wouldn't mind
seeing some real-life examples of how to separate logic and interface
cleanly, and speed up development.

Thx
JD.



Mon, 30 May 2005 20:40:16 GMT  
 Newbie: Organising a website using PHP

Quote:
> Do you know of good articles about how to go doing this? I'm currently
> looking at PHP templating systems along with Zope, and wouldn't mind
> seeing some real-life examples of how to separate logic and interface
> cleanly, and speed up development.

Here is one article about fasttemplate use:

http://www.phpbuilder.com/columns/sascha19990316.php3

For information about Smarty you can look at its website:
http://smarty.php.net

For information and few examples about TemplateTamer, look at the
TemplateTamer wiki:

http://www.templatetamer.org/

TemplateTamer started as a way of automating use of TemplateTamer, so you
can think of it as a bit higher level. Here are some sample pages generated
with TemplateTamer:

http://www.tuborg.hr/ (it takes some time toload initial flash, but look at
Tuborg No 1.)
http://www.moj-posao.net/

I would also try to answer all TemplateTamer relates questions.

rush
--
http://www.templatetamer.org/



Mon, 30 May 2005 21:37:02 GMT  
 Newbie: Organising a website using PHP

Quote:
> TemplateTamer started as a way of automating use of TemplateTamer, so you

excuse my careless fingers. it should be:

TemplateTamer started as a way of automating use of fastetmplate, so you

rush
--
http://www.templatetamer.org/



Mon, 30 May 2005 21:42:06 GMT  
 Newbie: Organising a website using PHP
I think of PHP as being best-used to inject dynamically generated content
into a site that /mostly/ is built using straight HTML or XML.  The only
site that I built "entirely" with PHP was the very first one I did, as an
experiment like you are doing.  It is far faster to build the site using a
regular HTML editor (Adobe GoLive, e.g.) and then "squirt" the necessary
PHP coding into it.

The whole file has the extension ".php" by necessity, but most of it isn't
written from scratch.  

When there's a large site to be done, I usually put all of the PHP material
into a separate directory.  Each "content" directory has a "global_inc.php"
(or somesuch) which simply includes the main-include file (whereever that
may be relative to "here"), which in turn includes all of the classes and
other garbage that's required.

When you do get to the part of building table-tags and all that jazz, the
book I refer to most often is "MySQL/PHP Database Applications" by Jay
Greenspan and Brad Bulger.  But I used that mostly for the ideas.

The cornucopia, of course, is the Internet itself.  "Do not do a thing that
has already been done" if you can legally cabbage it from someplace else.

Quote:

> As a web designer I am making the transition from designer to developer
> and am studying PHP and MySQL at present with apache setup locally for
> testing purposes.

> Before when I have designed a website I often used Dreamweaver templates
> to organise my site making site wide updates quite fast.

> I am starting to learn the basics of PHP in terms of syntax, functions and
> classes but wanted more information in terms of the organisation of a site
> using PHP.

> Using PHP to build a small web site would the best approach be to have one
> file containing the 'template' code (eg common.php)and each page calling
> functions from the common file to build the layout. Eg the common file
> contains a function which writes the navigation bar for a page. And
> content specific to the individual page is laid out between these
> functions?

> Or do programmers tend to put the layout code straight into a database
> with the code being called from there?

> Can anyone point me to a diagram or page or something which shows how
> developers might organise a site and how each newly created page would be
> created.



Mon, 30 May 2005 23:36:21 GMT  
 Newbie: Organising a website using PHP

Most modern sites nowadays use simple templates ('include' files) and CSS
stylesheets and XML. There are probably as many ways to do something as
there are people in this newsgroup and of course everyone will have their
own opinion. I myself use basic 'include' templates with stylesheets, XML
and mySQL. Nothing important is stored in the database, as an example none
of my page templates or critical site info is stored in the DB, this in "my
experience" is bad, I've had databases 'go for lunch' on me and then no one
can load the website.

Cheers,

TW

Quote:
> > >It is workable,and many sites especially older ones
> > > are built that way, but it gets more and more messy as your site
grows,
> > gets
> > > more complicated, or both.

> > If this is the case which approach do the more modern larger sites take?

> Well, you can do it as descibed, and I am afraid that if I answer this
> question you are going to conclude that I am using hard selling practices
on
> you :).

> Also I would not like to start the religious war about this since one
thing
> can be accomplished in many ways, and different people have different
> approaches. But many bigger or complex sites do use some sort of
templating,
> and if your site is going to grow, I would recommend you to use some sort
of
> templates.



Tue, 31 May 2005 02:47:31 GMT  
 Newbie: Organising a website using PHP

Quote:

> As a web designer I am making the transition from designer to developer
> and am studying PHP and MySQL at present with apache setup locally for
> testing purposes.

> Before when I have designed a website I often used Dreamweaver templates
> to organise my site making site wide updates quite fast.

PHP is for dynamically created content, and as such it produces will
produce a load (sever & bandwidth) on each page impression (... though
there are ways being developed).

If you are looking for relatively static content use one of the numerous
programs mentioned in the thread or...

write your own using PHP - a set of simple <<EXPRESSIONS>> in the
original that can be replaced using regex - and saved to a static HTML
file (this could even be done on-site)

The question really is what do you want to do - and what is the best tool
to do it ! (and if time is money... what tool do you understand!!)
--
Cheers, Kester



Tue, 31 May 2005 06:05:05 GMT  
 Newbie: Organising a website using PHP

Quote:

> but how would a developer approach a small php website without
> the use of a 3rd party app like templatetamer...

The easiest way is to write a simple wrapper.  Take a look at my
Web site:

http://www.ncbase.com/display.php

The wrapper includes six functional areas:

--------------------------------------------------------------------
Site title                      |  Link to printer-friendly version
--------------------------------------------------------------------
Main menu
--------------------------------------------------------------------
Context   |  Content
menu      |
--------------------------------------------------------------------
Main menu again
--------------------------------------------------------------------

Each functional area (except stie title, which is static) is the output
of a different function, which either takes no arguments (main menu)
or takes ID of the current page as the argument.  The content display
function obviously selects content from the database based on the ID,
the context menu function displays links to several other documents,
whose category association matches that of the current document, etc.

Obviously, this is a rather simplistic example, but that's what you
were asking for, right?  :)

Cheers,
NC



Tue, 31 May 2005 06:07:21 GMT  
 Newbie: Organising a website using PHP
index.php is the template.
functions.inc.php holds common code.
default.php is the individual content.

Use xhtml and valid css (esp. divs) to seperate presentation from content.

You'd want to add error checking and defaults to all this.  However, a good
developer follows a simple rule:

Re-use before buy before build.

------------------------------------------------
<?

// index.php

require_once('./functions.inc.php');

$page = $_GET['page'];

template_header();

require_once("$page.php");

template_footer();

?>
------------------------------------------------
<?

// functions.inc.php

function template_header() {
    echo '<html><head></head><body>';

Quote:
}

function template_footer() {
    echo '</body></html>';

Quote:
}

?>
------------------------------------------------
<?

// default.php

    echo '<p>Content</p>';

?>
------------------------------------------------
Result:

http://localhost/index.php?page=default

<html><head></head><body>
<p>Content</p>
</body></html>
------------------------------------------------


Quote:
> As a web designer I am making the transition from designer to developer
and
> am studying PHP and MySQL at present with apache setup locally for testing
> purposes.

> Before when I have designed a website I often used Dreamweaver templates
to
> organise my site making site wide updates quite fast.

> I am starting to learn the basics of PHP in terms of syntax, functions and
> classes but wanted more information in terms of the organisation of a site
> using PHP.

> Using PHP to build a small web site would the best approach be to have one
> file containing the 'template' code (eg common.php)and each page calling
> functions from the common file to build the layout. Eg the common file
> contains a function which writes the navigation bar for a page. And
content
> specific to the individual page is laid out between these functions?

> Or do programmers tend to put the layout code straight into a database
with
> the code being called from there?

> Can anyone point me to a diagram or page or something which shows how
> developers might organise a site and how each newly created page would be
> created.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.408 / Virus Database: 230 - Release Date: 25/10/2002


Tue, 31 May 2005 08:03:49 GMT  
 Newbie: Organising a website using PHP

Quote:

> I think of PHP as being best-used to inject dynamically generated
> content into a site that /mostly/ is built using straight HTML or
> XML.  

Another equally good use for PHP is as a tool to build the back-end
of a site, which will only be used by the author(s) or maintainer(s)
of the site, but the end result available to the reader will be static
HTML.  Movable Type and Discus (both are written in Perl though) use
exactly this approach for weblogs and forums, respectively; Perl-driven
scripts are only used when posting entries or comments.  The viewable
blog pages of forum discussions are all static...  

Cheers,
NC



Wed, 01 Jun 2005 07:30:44 GMT  
 
 [ 19 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Newbie to PHP - Displaying local PHP Files

2. FW: [PHP Classes] MetaL - a XML based meta-programming language developed using PHP

3. Good PHP/MySQL content managment system for personal website

4. PHP website from design to deployment

5. PHP and website

6. SAPI version of PHP, safe for production websites on IIS 5.0

7. Organising a program or library in files

8. Using websites without browser

9. Websites created using Clarion

10. Using labview to read html code of websites

11. Using search fields on websites

12. Website Password Authentication using Expect

 

 
Powered by phpBB® Forum Software