Home arrow PHP arrow Page 4 - Building a Site Engine with PHP, Part 1

The Template Got All GUI - PHP

Content management systems are becoming very popular, but what if you took it a step further than that? Thatís exactly what I plan to show you how to do in this series of articles. Iím going to explain how to build a site engine. A site engine is a core code base and database that can run multiple sites that are completely different while all running in unison, using all the same code, yet separate from each other.

  1. Building a Site Engine with PHP, Part 1
  2. First Things First
  3. Better Than your Local Rental Security Officer
  4. The Template Got All GUI
  5. Build It and They Will Come
By: James Murray
Rating: starstarstarstarstar / 136
June 07, 2004

print this article



Even though I've loaded all my blocks into a multidimensional array with keys that correspond to the block's placement, I still need a way for the engine to know what the coordinates made up of the array keys mean. That's why we need a template system and a loading system. What this system does is it looks at the array of loaded blocks and puts them in place on the template.

The templates are all XML based, to speed up the parse time, and with the new SimpleXML functions of PHP5, it makes it very easy to access the template data. The first thing you'd need to decide how you want the layout to look on the site. I prefer the traditional 3 column layout because it maximizes usable screen space. However it can be set up anyway you'd like, whether it's 3 columns wide, 1 column wide or even 5 columns wide.

When the multidimensional block array is made it looks something like this:

$blocks[1] - all the blocks in column 1

$blocks[2] - all the blocks in column 2

$blocks[3] - all the blocks in column 3

And so on until the final column. As you can see, the array key determines what column of the layout the blocks will show up in. The rows are just the same as the columns, and each of those arrays are sorted in the order that the blocks with be outputted from top to bottom by specifying the row as the key. Consider the following:

$blocks[1][1] - the top block in the first column

$blocks[2][3] - the third block in the second column

$blocks[3][1] - the top block in the third column

Here's a small visual mock up of the layout that contains 3 columns 2 blocks in column 1, 2 blocks in column 2, and 1 block in column 3.


It's pretty simple and logical when you think about it.

The template file also includes the look of the blocks, which also contains tags that will be replaced with the data that the block has such as the title and the block content. The blocks are actually each a separate file that is linked to the database by the file path then called through the plug-ins. The reason for this is because you might have a block that contains no PHP, just some HTML such as a menu block. So we replace the block template content tag with an include of the block file when the block is loaded. The blocks are by far the most confusing part of the entire site engine, but while working on it, you'll get to know and understand how it works a lot better.

>>> More PHP Articles          >>> More By James Murray

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: