Building a Site Engine with PHP, Part 4 (
Page 1 of 4 )
In the last three articles we went over a basic idea of how a site engine works,
how to build the plug-in, module, and block systems, the basic directory structure,
the database structure, and the authentication methods. In this, the fourth article,
we’ll be going over the template system, and the basic page loading methods. So,
let’s go ahead and get started.XML and HTML and CSS, Oh My!
XML is a really cool language to use for a template system. Coupled with PHP5,
you almost have a hybrid of languages that I like to refer to as Object-Oriented
HTML. It makes you want to say “OOH!” and "Ahh!".
The templates are made up of an XML document that contains each piece of our
layout as a separate XML element in HTML form. At that point most people say “What!?”
Well, for each element, we embed the HTML as CDATA. What we end up with is a Header element that contains the HTML from the <html> to the spot that your first content column starts. Then there is the Body element that contains the area that will hold all our content columns. Following
that we have the Footer, which contains our content to the </html>. Then we have our three column elements which hold the HTML for each of our
content columns, then the Block element, which contains the HTML for the layout
of our blocks.
Basically this is what the XML document will look like:
<template>
<header> <![CDATA[]]></header>
<body> <![CDATA[]]></body>
<footer> <![CDATA[]]></footer>
<column1> <![CDATA[]]></column1>
<column2> <![CDATA[]]></column2>
<column3> <![CDATA[]]></column3>
<block> <![CDATA[]]></block>
</template>
Not too hard to follow. If we were to break it down into the order it is loaded,
it would look like this:
<header>
</header>
<body>
<column1>
<block>
</block>
</column1>
<column2>
<block>
</block>
</column2>
<column3>
<block>
</block>
</column3>
</body>
<footer>
</footer>
The example above shows only one block in each column, but chances are most pages
will contain more than one block per column. Here is a rather crude example of
what a finished template file would look like.
<template>
<header><![CDATA[<html>
<title><!title></title>
<body>
<div style="width:100%;text-align:center;">header!</div>]]></header>
<body><![CDATA[<div style="width:100%"><!content></div>]]></body>
<footer><![CDATA[<div style="width:100%;text-align:center;">footer!</div></body></html>]]></footer>
<column1><![CDATA[<div style="width:25%;float:left;text-align:center;"><!column1></div>]]></column1>
<column2><![CDATA[<div style="width:50%;float:left;text-align:center;"><!column2></div>]]></column2>
<column3><![CDATA[<div style="width:25%;text-align:center;"><!column3></div>]]></column3>
<block><![CDATA[<div style="width:100%;text-align:center;"><!block_data></div>]]></block>
</template>
A real one would contain much more complex html, but for the sake of an example,
that does the job. It will work as a full template. As you can see there are a
few proprietary tags in the html, such as <!title>. We talked a little about those in the fourth part of the first article. Now is the time to talk a little more about them.
| | Discuss Building a Site Engine with PHP, Part 4 | | | | | | | Suddenly the code is no longer indented. Is there a whitespace issue with PHP5 that... | | | | | | I agree, this part 4 was really a disappointment.
Hope the finale is a... | | | | | | I must agree with the above commments.
Since part 3 the quality of the articles has... | | | | | | I hope things gets easier to understand when I've read the full article.
As posted... | | | | | | in article 3: where do I have to put the blocks and authentification plug-ins?
in... | | | | | | IN article 3:
You have code for two different plugins, "auth" and "blocks".
Now... | | | | | | what about the replace() function? where do i have to put it?
... and that... | | | | | | the load_template() function tells you exactly where your xml file... | | | | | | I plan on rewriting this article due to the fact that it's a new writing style... | | | | | | >AND yes, if you read all the articles with attention, you'd know what to do with... | | | | | | First off, I don't consider myself an extremely knowledgeable user of PHP. That... | | | | | | "What are the file names of the Templates and XML plug-ins?"
"... and XML class... | | | | | | It's like trying to plug an episode of Jerry Springer
into Oprah show, they might... | | | | | | Has anyone tried this yet? I know some are dissapointed, but I think that it's... | | | | | | Ok, well Im treating this article as a guide to how to do it. I dont run PHP5 so I... | | | | | | I agree that a download of the sample code would be FANTASTIC. I think that would... | | | | | | Yeah thats pretty much it really, not the hardest thing I'll have done this month... | | | | | | this IS a guide on how to do it, this isn't a "heres the source code for a finished... | | | | | | I would like to thank you for writing these articles, the quality is going down a... | | | | | | I'll say that- it got me thinking. Overall this has been a big eye-opener to me, as... | | | | | | That is great that you the system up and running. Would it be possible for you to... | | | | | | why would the sql function (inside sql.inc.php) not have any arrguments. I couldn't... | | | | | | To get the sql function to work declare $config global in the function sql()... | | | | | | This is my current core.inc.php, shows the changes made to support the sql inc... | | | | | | So maybe you can add source to download ? with all files and mysql dump? | | | | | | Thanks a bunch Simon. That seems to clear it all up. It’s nice to see some progress... | | | | | | Well I made some progress on the parser today, it seems to do what the simpleXML... | | | | | | simon ...wow... only 3 weeks... could you share with us what tutorials/books you've... | | | | | | I'd really like to see a completed source package also. | | | | | | as would I! | | | | | | Well I dont have any PHP books, the online suport at php.net is very good as it is,... | | | | | | a complete working package would be very helpful to understand how it works | | | | | | The author made a comment saying he didn't want this to be a "heres a site download... | | | | | | you read my mind :) | | | | | | I'm studying this articles for a couple of hours and i have a question.
You... | | | | | | Any thoughts on the above comment? | | | | | | I don't think that these articles should be always targeted toward beginners. If you... | | | | | | Exactly, this is a guide, a tutorial. If you just want to download a working CMS,... | | | | | | you can make them yourself in your core.inc.php
this is my... | | | | | | you can write small modules which creates an instance of the plugin
Lets look at... | | | | | | Hi Simon,
Ive been having some problems getting your PHP4 simple xml parser... | | | | | | >>> Post your comment now! | | | | | |
|
 |