Currently I have a legacy based non-MVC php framework which I need to update to support a leveling/feature system.
I want to have two modes, a normal mode ( the current mode ) and a level based mode where I control what features are included - low, medium, high tiers.
For example, the low tier will not support google maps, while the medium and high tiers will. The layout varies between the tiers as well, so I have to have a template master file for each tier in addition to my current template.
And there is a difference between the high tier in level mode and the current mode, in that there are certain things included in the high tier, but there are unlimited features in the current mode ( non-level based ).
Currently the system structure is laid out as such:
templates/
default.php
includes/
branding.php
css.php
js.php
map.php ( google map )
If you visit index.php
or contact.php
it just does a require_once APP_PATH . 'templates/default.php'
I know that isn't the most ideal type of environment since it isn't MVC based but that's what I'm stuck with ATM.
The templates/default.php
looks something like:
<!doctype html>
<html>
<head>
<?php include APP_PATH . 'includes/branding.php';
</head>
<body>
<?php
switch ( filename ) {
case 'map':
include APP_PATH . 'includes/map.php';
}
?>
<?php
include APP_PATH . 'includes/google.php';
?>
</body>
</html>
So a fairly oldschool type of template file.
In order to support the leveling system I suspect I'll have to alter my framework structure to something like..
templates/
level-0.php
level-1.php
level-2.php
level-3.php
includes/
branding.php
css.php
js.php
Now in my configuration file I'll have to define some constants, such as..
define('LEVEL', 1);
define('TEMPLATE_FILE', APP_PATH . 'templates/level-' . LEVEL . '.php');
default.php
becomes level-0.php
and for the tier based templates, they are 1, 2, 3 respectively.
So now when I visit a page such as index.php
or contact-us.php
I would include the TEMPLATE_FILE
constant:
require_once TEMPLATE_FILE
- Is this ideal? Are there any drawbacks?
If I go with this method I'll have 4 separate template files and that's fine. So for example the lowest tier won't include the map
include while the highest tier will.
Another issue I'm concerned with is sub-branching, is it ok to branch out within the include files? An example is that the lowest tier won't have a favicon. The favicon element is in includes/css.php
, so I'll have to branch within that file:
includes/css.php:
<link rel="stylesheet" type="text/css" href="main.css">
<?php if ( LEVEL !== 1 ) { ?>
<link rel="shortcut icon" href="favicon.ico">
<?php } ?>
- This might get a bit messy, but it saves me from duplicating css.php everywhere and having to update 4 instances of it. Is this ideal?
I apologize for the loaded question, appreciate any advice.