Please note: This is an unpublished site and we are making changes - glitches still!!!

The index.php file 

One advantage of a modular, object oriented, template based system is that index.php does not normally grow too big. We could start with a very simple one... but why bother hiding the secrets! We will display the real one from this very site:

index.php

Yes, well, we think it is a bit lengthy...  but please note that there are quite a few comment lines.This file will cover most of what we will need.

As you can see we have a few inclusions. We will need the Registry class immediately as well as the  CmsSmarty. The Registry singleton stores the settings of our application. We have already covered the Registry class and  how it is used but here it is again for your perusal.

Note: You do not need to grasp the inner workings of the libraries below. When you have got your site up and running you can have a look at them. Please remember that the Registry.class.php should be placed inside the lib directory and the utils.php  file inside the include directory.

Registry.class.php

The Utils file is an old-fashioned collection of small functions that we have left out out the OOP. Nothing wrong with that!

utils.php

The template handling class is a simplistic derivation from the Smarty class.

CmsSmarty.class.php

As you can see most of what it does is use the Registry settings to set up the main instance of Smarty. We have, however, added  some exception handling. What the exception handling does is make old-fashioned errors throwable so you can use try..catch structure in cases that do not inherently support catching errors. Go have a look at the Smarty plugin to see how the functionality is used in an include_once error handling. Please save this in the lib directory.

If you want to add exception handling as a separate class here it is:

ExceptionThrower.class.php

Good Lord, we have forgotten the two small html files that we need to test whether our system really works. The html/menus.html is something like this

Please note: these files do not exist yet so the 'plus' will show an error message and the [code] will show a blank popup.

menus.html

and the html/test.html can be anything. Lets be simplistic

test.htm

Testing the system
 
Now you should be able to point your browser to the main page. If the system works we will move on and jump to dynamic pages that get their content from the database.

Security benefits

One benefit of the system we have built is that our index.php is the only entry point into the system as it is the only php file that contains a runnable script. The rest of the system is made of classes that are not runnable. Therefore it is very easy to add, say, XSS filtering code that prevents any attempts to get deeper into the system. We will have a look at that a bit later.