WANTED: Best PHP System Design

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

WANTED: Best PHP System Design

Post by harrisonad »

ok guys, ever sinced i intend to crave for more of you and your brains which i envy to have.

now i need some advise from you.

i am starting on a php project and to my delight in new system design,
i changed the way i deliver the web page itself to the browser ( that's how i perceive it ).

here are the steps i implemented so far:

1. some basic php start but without:
<HTML>
<HEAD>
<TITLE>
of that kind. instead some simple page preparations i have learned so far.
2. Here comes navigational images, sidebar menus, and footers.
3. Then the dynamic content:
dynamic because everything here just comes(read) from files (usually with "./contents/" directory). These files are just HTML files but without any extensions. The file to load is determined by query string(such as "index.php?page=home&mode=user").

Yeah, i know that i may sound as a beginner. that is why i need some comments from you. Or, it is much better if you recommend some strategies to make this work better.

thank you in advance

:idea:
ldomingues
Forum Commoner
Posts: 41
Joined: Fri Aug 06, 2004 1:15 pm
Location: Portugal

Post by ldomingues »

That's reinventing the wheel...

Why not use a templating system (like smarty) and a database to store contents?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

If you separate your HTML (./contents/) from your control code (index.php) the you can start to build a clean system. Put your HTML headers, navigational images, sidebar menus, and footers in the content directory as well as separate files. Let the control code choose what to include based on the request (that's the "page=home&mode=user" part).
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

I would also recommend smarty
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I think Smarty is overkill for what you are doing. The sImplest way is to use PHP templates which are just PHP files with no program control logic in them (you can use simple loops if you want). For example:

Code: Select all

<html>
<head>
<title><?php echo "$SiteTitle - $PageTitle"; ?></title>
</head>
<body>
Where to use it like:

Code: Select all

$SiteTitle = 'My SIte';
$PageTitle = 'My Page';
include "./contents/header.php';
Or you can use a str_replace approach with is also pretty simple, where you template looks like::

Code: Select all

<html>
<head>
<title>{SiteTitle} - {PageTitle}</title>
</head>
<body>
Where to use it like:

Code: Select all

$str = get_file_contents("./contents/header.php');
$str = str_replace('{SiteTitle}', 'My SIte');
$str = str_replace('{PageTitle}', 'My Page');
echo $str;
You can write a simple class for these with an interface like:

Code: Select all

class template
{
function template($filename)
function set($name, $value)
function toHTML()
}
Look at some of the simpler template classes in script archives to get ideas.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

There's some discussion here about InterceptingFilter (I made the same post on this forum but it didn't take off) which contains my own thoughts about framework design.
Post Reply