Re: Question about template systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 03, 2009 at 09:01:06AM +0000, Matthew Croud wrote:

> Hello,
>
> First post here, I'm in the process of learning PHP , I'm digesting a
> few books as we speak.
> I'm working on a content heavy website that provides a lot of
> information, a template system would be great and so i've been looking
> at ways to create dynamic data with a static navigation system.
>
> So far, using the require_once(); function seems to fit the bill in
> order to bring in the same header html file on each page.
> I've also looked at Smartys template system.
>
> I wondered how you folk would go about creating a template system ?

Here's a simple way of doing this: Set up a full page of HTML, with the
header, footer and all that stuff. But leave the center (content) part
of the page blank. You can call what you just built a "template". What
goes in the center could be called a "view". In the center of the page,
put a call like this:

include($view_page);

When you go to display the page, do this:

$view_page = 'apples.php';
include('template.php');

When the template page is included, it will, in turn, the view page
(apples.php) will get included. This works well if you want the same
basic look for all the pages of your site.

Just one way to do it.

>
> My second question might be me jumping the gun here, I haven't come
> across this part in my book but i'll ask about it anyway.  I often see
> websites that have a dynamic body and static header, and their web
> addresses end like this: "index.php?id=445" where 445 i presume is
> some file reference.
> What is this called ?  It seems like the system i'm after but it
> doesn't appear in my book,  If anyone could let me know what this page
> id subject is called i can do some research on the subject.
>

Most likely, index.php is what is called a "front controller" (look it
up). The "id=445" is a GET variable being passed to index.php. The
index.php file checks this variable and decides which page to display.
It could be a page called "anything.php", but index.php knows that when
id = 445, it should display this page.

An awful lot of websites use a model-view-controller (MVC, look it up)
system using a front controller. There are tons of these about. My
personal recommendation for about the lightest weight of these is
CodeIgniter (codeigniter.com). Being lightweight also allows you to look
at its code and easily understand what it's doing and why.

Paul
-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux