
The PHP Sweet Framework is designed to give as much flexibility as possible while maintaining a simple and consistent method of configuration.
A site is broken up in to a 3 layers, configuration, processing and display.
To configure a new site you will first need to create a site configuration file. This is used to set various static setting such as database user name and password, template name and site specific directories. A basic example of this would be:
<application name="mysite"> |
This is based on a typical linux hosting environment where each site has its own directory and the sites web pages are contained with in a subdirectory such as httpdocs.
This allows for the code and configuration to be outside of the document root, and there for not accessible from the outside using a web browser. This increases the security.
Within the ‘session_root’ folder a directory is needed with write permissions called ‘session’.
To create a simple site where all the pages are essentially the same with various ‘content’ only a single page needs to be configured. All page configuration files reside within the ‘page_repository’ directory as configure in the site configuration.
All sites will require a ‘content page’. This the default page layout. A simple example of this would be:
content.xml <page name="content"> <module name="content" id="page_content" content=%1/> <module name="menu" id="mainmenu" menu="mainmenu"/> <template name="index_main"> <assign var="header" value=$page_content.header /> <assign var="page_content" value=$page_content /> <assign var="mainmenu" value=$mainmenu /> </template> </page> |
The above tells phpSweet to load both a content module and a menu module. %1 represents the first word on the url. For instance www.mysite.com/index.html would mean that %1 is then equal to index as the .html is automatically removed.
A menu is then loaded from the menu description file ‘mainmenu.xml’ which can be found in the menus folder as set in the site configuration.
The template section is used to tell phpSweet which template to load, and what variables need to be assigned. In the above example index_main is the name of the template and will cause phpSweet to load the index_main.tpl file. An array is then set with the header details loaded from the content file called ‘header’ ($header in smarty) and the page body in to ‘content_body’ ($content_body) in smarty. The menu module also creates an array of the menu items and it placed in the ‘mainmenu’ variable.
The phpSweet content module uses a very basic xml file to describe all static content pages. This should generally be considered to be the main body of the page without any navigation. For example a simple index page would be:
index.xml <content > <header> <pagetitle>My Page Title</pagetitle> <description>My Page Description</description> <keywords>My Page Keywords</keywords> </header> <body><![CDATA[ **** HTML Content **** ]]> |
If no name is passed to the content module the default is ‘index’. Otherwise the name passed is used to load the xml file. For instance if the url was www.mysite.com/aboutus.html, then the content file aboutus.xml would be loaded.
The phpSweet menu module like the content module loads the menus from an xml file. These files are located in the directory specified in the configuration, usually this would be called ‘menus’.
A basic example of a menu file would be:
<menu template="mainmenu"> <item url="index">Home</item> <item url="aboutus "> About My Site</item> <item url="contactus">Contact Us</item> </menu> |
As you can see this file contains 3 menu items, the text is passed to the template unchanged so it is generally a good idea to add the .html to the end of the url with in the template though this is not required. However it could also be included with in the menu ‘url’ within the menu file.
phpSweet allows for the creation of pages with different modules. For instance if you wanted to have a home page without the main menu for use as a spash page then you would simple create ‘page’ xml and ‘content’ xml files called index. The content would be the same, but the page file would be as follows:
index.xml <page name="content"> <module name="content" id="page_content" content=index/> <template name="index_splash"> <assign var="header" value=$page_content.header /> <assign var="page_content" value=$page_content /> </template> </page> |
As you can see this page also uses a different template, this is simply to make life easier but using smarty it also possible to detect that the menu array is not set and there for not process it. This applies to any page. If you wish to over ride the default functionality described in the ‘content.xml’ simply create a custom xml file of the name of the new page and phpSweet will process it automatically.
Sometimes you may wish to split your site in to a number of subdirectories. With phpSweet this is not a problem. Simply create a ‘page’ xml file with the same name as the subdirectory in just like the content file described above. Even %1 is left the same. phpSweet will then use this file, and pass the next part of the url as the ‘page name’. For example if you wanted the url www.mysite.com/examples/example1.html then the page ‘examples’ would be loaded, and then the content ‘example1’.
The following is a basic template example containing a single menu and space for the body content.
<html> <head> <title>My Site - {$header.pagetitle} </title> <link rel="stylesheet" type="text/css" href="/reset-min.css"> <meta name="generator" content="phpSweet"> <meta name="author" content=" "> <meta name="keywords" content="{$header.keywords}"> <meta name="description" content="{$header.description}"> </head> <body> <div id="header"><img src="/images/titleimage.jpg"></div> <div id="page_body_center"> <div id="page_body"> <div class="nav_container"> {foreach from=$novelmenu->items key=k item=menuItem} <a href="/novels/{$menuItem.url}.html">{$menuItem.text}</a> {/foreach} </div> <!-- Start body content --> <div id="body_content"> {$page_content} </div> <!-- end body content --> |
I have highlighted the smarty template code in green, for help and more examples of the use of Smarty visit www.smarty.net