Here is a simple example to demonstrate an easily maintainable way of setting page loading based on the current URL. It holds all of your available pages in an associative array .. This could easily be pulled from a database.
I have also included template code to generate a simple menu for you.. You could of course just construct the URL’s by hand in your templates if this does not serve your needs.
For brevity, I did not include any css or table structure for the index.tpl file.
index.php
| Code: |
|
<?php /** * Website controller * @author www.ideamesh.com */ //Include and instantiate Smarty //Setup the url var we are looking for to control page display //Using the $_REQUEST scope so that the page can be passed in via $_POST or $_GET //This array holds the relationship between the page variable and the template to load.. This info could also be retrieved from a db //Check if the requested page was found in the menu //Assign info to Smarty and display |
index.tpl
| Code: |
|
{include file=”menu.tpl”} {include file=$template} |
menu.tpl
| Code: |
|
{* We generate the menu list from the available pages in the menu *} <ul id=”navigation”> {foreach key=url_val item=template_name from=$menu} <li> <a href=”{$SCRIPT_NAME}?{$page_var}={$url_val}”> {$url_val}<br /> </a> </li> {/foreach} </ul> |









































