Web Hosting Talk







View Full Version : PHP - Template Presentation Probs ...


quantass
08-14-2005, 08:35 AM
I've created my own simple Template Class. I dont know if I'm going to use this very much but I've broken up the display into 5 regions: TOP landscape navigation area, BOTTOM landscape nav, LEFT skyscraper nav, RIGHT skyscraper nav, and a large CENTER body area. The Template Class is responsible for displaying all regions to produce a complete website. I've set it up so that every webpage has 2 layers, a .php (presentation page with HTML and calls to the class members) and a .cls.php (code-behind logic page that contains a Class to support the front-end presentation page). When the user hits the .php page this creates a new instance of the Template Class:
-------
(MyCenterPage.php)
<?php
include("WebsiteTemplate.cls.php");

$mypage = WebsiteTemplate();
?>

<html>
<body>
<h3><?=$mypage->Center->getData();?></h3>
</body>
</html>
-------

The Template Class has a constructor which allows it to define the 5 regions -- just supply the regions presentation page and it will handle the job of loading/displaying the presentation page in the proper region and creating a new instance of the respective code-behind class so that I can access the region's object members from within my current page:
-------
(MyCenterPage.php)
<?php
include("WebsiteTemplate.cls.php");

$mypage = WebsiteTemplate(); // By default the template assumes the Center region is for this current/owning presentation page and all other regions are DEFAULT settings.

$mypage->Top->setText("Tech Page");
$mypage->Left->removeText("Sales");
?>
<html>
<body>
<h3><?=$mypage->Center->getData();?></h3>
</body>
</html>
-------

When the above page is finished the Template Class composes the final webpage in full and is presented to the user with all 5 regions in place (with the modifications to the Top and Left regions established in the MyCenterPage.php file). If i dont want any particular region I just set the constructor's region parameter to NONE and this remove's the region from the template allowing the other regions to spill into the area as if it never existed. Because I will be making all pages into .php/.cls.php combos basically any page i create can be slapped into a region area and accessed by the owning page.

Finally, I wanted to allow myself to simply type my HTML code as i normally would without having to leave out <HTML> or <HEAD> tags. Basically the template just grabs the presentation page and inserts it into the respective region and I dont think browsers would appreciate seeing multiple <HEAD> tags in various table cell regions. Because of this the template class, just before displaying, removes all redundant tags (<HTML, <HEAD>, <BODY>) and "moves' head content from all 5 regions and stacks them into a single head area. This creates a unified single page both infront and behind.

Now my problem, the owning page (in my case: MyCenterPage.php as shown above) just displays its presenation data as is and it expects the Template class to place it into the proper region. I do this with Output Bufferring which is set to ON just before the constructor completes. Once the page has outputted in full i rely upon the Template Class's Destructor or the Output Buffer's Callback function (ie. ob_start($this, 'callback')) to store the output for the current page. The problem Im having is the presentation of the other regions...

I wait until within the Destructor or the Output Buffer Callback function to load the respective presentation files and this is a NO NO apparently. The reason i wait till then is because i want to give the owning page a chance to make modifications to the other regions via their class members (ie, $mypage->Top->setText("Tech Page"); ). I have no clue when the owning page has completed its modifications to the other regions so i wait until the owning script itself is ready for output before assumming its time to load the other region presentation files, which will consider all the modifications set by its respective class properties. Unfortunately using:
---
ob_start()
include("TopRegion.php");
$str_top_region_html = ob_get_clean();
---

generates a PHP error that ob_start() is invalid within the callback function and the Destructor area just silently refuses to execute any of the above.

Now i realize I can just have the owning page slap in some additional method call to the Template Class to indicate it is complete near the end of the presentation page or perhaps something to indicate it is completed modification with the other regions near the top but IDEALLY i dont want this extra fluff. I want to make the presentation page as lean as possible. I want the other regions to feel transparent unless called upon from the owning page.

Is there some other callback or event i can use within my Template Class to indicate it is time (the owning page has completed its duties) to retrieve the presentation files for the other regions ? Maybe something that is called just before the destructor but allows me to use ob_start/end and to use include() ?

Thanks.

The PHP files will be running at work with the following server specs
Windows 2003 Server
IIS 6.0
PHP 5.0.4
Dual P4 CPU

At Home I'm using:
Windows XP Pro
IIS 5.0
PHP 5.0.4
P3 @ 450MHZ