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

Creating the Environment

The first thing to do is to create an empty application development environment. Without going into the basic details let’s see the structure here. In Linux/Unix it is common to have a symbolic/soft link but in Windows it is easier to rename the Smarty-x.x.xx directory to "smarty".  As of writing this the Smarty templating engine is in version 3.1.x. Whatever the version might be the instructions should be the same.
directories.txt
Some explanation is obviously necessary.
/[web application root] is the root of the application containing the index file (index.php) and the .htaccess file 
/admin is reserved for future site administration
/cache is reserved for possible future Smarty intelligent caching
/configs is reserved for configuration settings
/css should be self-explanatory
/files contains images, videos, sounds, pdfs etc we want to serve to the world. This needs to be writable!
/include contains some simple included things
/js contains the Javascript libraries 
/libs contains various libraries like the Smarty library.
/modules contains the modules we develop. We will have a closer look at the directory structure later
/templates contains the main source templates excluding the module templates
/templates_c contains the compiled templates. This must be writable by the web server software. 
 
To make the files and templates_c directories writable you must set their rights to 0x777 in Linux/Unix. Okay, here is a skeleton you can run in your website root directory in your linux/freebsd shell:
create_dirs.sh
 
We will have a few additional directories and may need more depending on our needs. NOTE: It is not a good idea to have all these accessible under the web root. For the sake of simplicity we have placed them all there. After you have got the idea it is totally up to you to create a better directory structure. 

Tasks to do:

  • Create the directory structure and unpack the Smarty library under the libs subdirectory. Depending on your working environment either rename the Smarty‑3.x.xx directory to "smarty" or create a symbolic link pointing to it.
  • Also make sure that your web server is allowed to write to the templates_c  and the files directory (with subdirs).
  • Get the latest JQuery library and copy it to the js directory

If you are planning to use Smarty for several applications it is a good idea to install it to a shared directory like /usr/local/lib/php/smarty and create a symbolic link to it. This way the updates to Smarty will be instant in all applications. If you are using opcode cache like APC this solution will also save some opcode cache memory.

Some basic decisions and assumptions

To know how to use system-wide resources like databases, directory paths and so forth we will make a decision: All globally accessible variables are stored in a  singleton instance of  class Registry. A singleton instance can only be created once and it is very suitable for storing system wide data like settings and status during the various phases of page load. You can have a look at our lonely Singleton class by expanding the box below.
Registry.class.php
 
So what we will do is save the settings in the /configs directory with a good name, say "mysettings.txt" or something alike, read and parse it and store the stuff to the registry. For the sake of simplicity the structure of the file is like this:
# this is a comment
# db settings
dbhost = localhost
dbname = cmstutorial
dbuser = cmstutorial
dbpass = cmstutorial
# image settings (just an example)
thumbnaildir = images/tn
Now it is easy to write a small script that parses this script and stores the values to our Registry singleton. 
 
Note that we do have very little OO at this point yet. From an orthodox point of view we might, for instance, instantiate a "CmsApplication" object and have its methods perform the tricks below and save the configuration status internally. But for the sake of simplicity we will use a simple procedural method here. 
getconfigdata.php
 
To be able to use this function, create file "include/utils.php" and add the function into it. In the index.php script we might have something like this

include "include/utils.php";

getConfigData
("configs/mysettings.txt");

Okay, now that we have the directories in place and the most important utility function written we can start writing our CMS root class.