Page 1 of 1

WANTED: Best PHP System Design

Posted: Fri Oct 15, 2004 6:21 am
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:

Posted: Fri Oct 15, 2004 1:41 pm
by ldomingues
That's reinventing the wheel...

Why not use a templating system (like smarty) and a database to store contents?

Posted: Fri Oct 15, 2004 2:13 pm
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).

Posted: Fri Oct 15, 2004 2:16 pm
by andre_c
I would also recommend smarty

Posted: Fri Oct 15, 2004 2:37 pm
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.

Posted: Fri Oct 15, 2004 4:52 pm
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.