lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP: MVC Demo
A framework I've come up for relatively fast, structured deploys of small dynamic websites or page suites. It can be used freely, but is intended more as a model or inspiration for others:

<?php

// start page time
$tx1 = microtime();

/* FILE INFO

MVC Demo

File: index.php
Last Update: Dec 2005
Author: Tom Atwell (klenwell@gmail.com)

NOTES:

This model makes use of a couple other files and function I've created:

FILE: build_navbar.inc.php
FX: rollover_menubar()

WARNING : without content files (meant to hold html) in a content directory on the
same directory level as this page, page will generate a warning.


/*______________________________________________*/

/* 1. LOCAL DRIVER ******************************/

// DOCUMENT SHORTHAND
define('iEOL', "\n");
define('iSEP', DIRECTORY_SEPARATOR);

// LITE VERSIONING
$_iSET['local_dir'] = 'DIRNAME';
$_iSET['beta_server_name'] = 'www.YOURBETAHOST.com';
$_iSET['live_server_name'] = 'www.YOURLIVEHOST.com';

// VERSION TREE - set document root path ($_iPATH['root'])
# local or beta
if ( $_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == $_iSET['beta_server_name'] )
{
$_iPATH['root'] = $_SERVER['DOCUMENT_ROOT'] . iSEP . $_iSET['local_dir'] . iSEP;
}
# live
elseif ( $_SERVER['SERVER_NAME'] == $_iSET['live_server_name'] )
{
$_iPATH['root'] = $_SERVER['DOCUMENT_ROOT'] .iSEP;
}
# catch
else
{
die('Invalid version -- server environment not clear. Check LITE VERSIONING settings');
}

// PATHS
$_iPATH['self'] = $_SERVER['PHP_SELF'];
$_iPATH['abs_self'] = __FILE__;
$_iPATH['super'] = dirname($_iPATH['root']) . iSEP;
$_iPATH['content_dir'] = $_iPATH['root'] . 'content' . iSEP;

// INCLUDE LIST
#require_once('project_driver.inc.php');
#require_once($_iPATH['root'] . '_engine/build_navbar.inc.php');
#require_once($_iPATH['root'] . '_engine/form_package.inc.php');
#require_once($_iPATH['root'] . '_engine/mail_package.inc.php');

/*______________________________________________*/


/* 2. MODEL (Data) ******************************/

// PUBLIC VARIABLES (configurable)

# HEADER
$page_title = 'TITLE_ON_PAGE';
$head_title = "HEAD_TITLE";
#$css = $_iPATH['root'] . 'css_bin/FILENAME.css';

# HTML
$_HTML['menubar'] = '';


// PRIVATE VARIABLES

# internal
$_serve = 'home';

// HEAD

# document settings
$_charset = 'ISO-8859-1';
$_favicon = 'http://firefox.no/favicon.ico';
$_title = $_PROJECT['name'];
$_keywords = 'Allied Portals and Engines,PHP,MySQL,internet,web,application,progressive,design';
$_description = 'This page was developed by Allied Portals and Engines. For more information, visit www.alliedportalsandengines.com';
$_css = 'http://localhost/AMVC/graphics_pack/css_bin/amvc_basic/_basic.css';

# HEAD settings
$_HEAD['doctype'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . "\n" . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$_HEAD['open_tag'] = "<html lang=\"en\">\n<head>";
$_HEAD['content_type'] = '<meta http-equiv="Content-Type" content="text/html; charset=' . $_charset . '" />';
$_HEAD['title'] = '<title>' . $head_title . '</title>';
$_HEAD['keywords'] = '<meta name="Keywords" content="' . $_keywords . '" />';
$_HEAD['description'] = '<meta name="Description" content="' . $_description . '" />';
$_HEAD['fav_icon'] = '<link rel="shortcut icon" href="' . $_favicon . '" type="image/x-icon" />';
$_HEAD['css'] = '<link href="' . $_css . '" type="text/css" rel="stylesheet" />';
$_HEAD['close_tag'] = '</head>';


// INCLUDE ARRAY

$_CONTENT_FILES = array
(
# GET ref -> file name
'home' => 'home',
'how to help' => 'help',
'contact us' => 'contact'
);

$_MENU = array
(
'home' => $_iPATH['self'] . '?serve=home',
'how to help' => $_iPATH['self'] . '?serve=help',
'contact us' => $_iPATH['self'] . '?serve=contact'
);

/*______________________________________________*/


/* 3. CONTROLLER ********************************/

// *** GET HANDLER

# empty or invalid GET
if ( !$_GET['serve'] || !in_array($_GET['serve'], $_CONTENT_FILES) )
{
$_serve = 'home';
}
# valid GET
else
{
$_serve = $_GET['show'];
}

# add path
$_iPATH['content_file'] = $_iPATH['content_dir'] . $_serve . '.inc.php';

# get navbar label
$_nav_label = array_search($_iPATH['self'] . "?serve=$_serve", $_MENU);

# build navbar
#$_HTML['menubar'] = rollover_menubar($_MENU, $_nav_label, 'menubar');


/*______________________________________________*/


/* 4. VIEWER ************************************/

echo $_HEAD['doctype'] . iEOL;
echo $_HEAD['open_tag'] . iEOL;
echo $_HEAD['content_type'] . iEOL;
echo $_HEAD['keywords'] . iEOL;
echo $_HEAD['description'] . iEOL;
echo $_HEAD['title'] . iEOL;
echo $_HEAD['fav_icon'] . iEOL;
echo $_HEAD['css'] . iEOL;

?>

<!-- Local Style Sheet -->
<style type="text/css">
<!--
body
{
background:#666;
font:1em Palatino Linotype, Book Antiqua, Palatino, serif;
}
#masthead
{
padding:20px 25px 10px;
border-bottom:1px solid #ccc;
}
#page
{
width:96%;
margin:0 auto;
border:8px solid #ccc;
border-width:0 8px;
background:white;
padding:1% 1% 0;
}
#footer
{
text-align:center;
font:11px/1.4em Verdana, Geneva, sans-serif;
border-top:1px solid #ccc;
padding:1em;
}

a { color:orange; }
a:hover { color:lime; }

#masthead h1
{
margin:0;
font-size:2.4em;
}
#masthead h4
{
margin:0 0 8px;
position:relative; top:-10px;
}

#content_table
{
width:100%;
}
#content_table td
{
vertical-align:top;
}
#content_left
{
text-align:right;
border-right:thin solid #ccc;
padding:1em 1em 1em 0;
width:22%;
}
#content_left
{
}
td#content_right
{
padding:1em;
}

#menubar
{
width:100%;
text-align:center;
}
#menubar a
{
color:black;
font:1.1em/2em Lucida Sans Unicode, Lucida Grande, sans-serif;
}
#menubar a:hover, a#current
{
color:orange;
text-decoration:none;
}
.rollover_menubar
{
width: 100%;
}
.rollover_menubar ul
{
margin-left: 0;
padding-left: 0;
list-style-type: none;
}

#home
{
font-size:1.2em;
margin:1em .5em;
text-align:justify;
}

#help h2
{
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
margin:0 0 8px;
}
#help h4
{
font-family:arial, sans-serif;
margin:0 0 4px;
}
#moreinfo
{
margin-top:15px; padding-top:8px;
border-top:1px solid #667041;
}

.entry
{
margin:0 0 16px;
padding:10px;
background:#f7f8f3;
border-bottom:1px solid #667041;
}
.entry h4
{
font-family:Trebuchet MS, Helvetica, sans-serif;
margin:0 0 6px;
}

.contacts
{
font-size:1em;
margin:2px 0 12px;
}
.contacts h4
{
font-size:1.1em;
font-family:Trebuchet MS, Helvetica, sans-serif;
margin:0;
}
.contacts h5
{
font-size:.9em;
font-family:arial, sans-serif;
margin:-2px 0 0;
}

#contact_form_panel
{
width:40%;
float:right;
margin:0px 10px 10px 10px;
padding:5px 10px;
text-align:left;
background:#f7f8f3;
border:1px solid #667041;
font:.85em/1.5em arial,sans-serif;
}
#contact_form_panel h3
{
margin:4px 0 0;
}
#contact_form_panel #meta_prompt
{
font-size:.9em;
line-height:1.2em;
margin:2px 0 6px;
color:#985950;
}
#contact_form_panel form
{
margin:0;
}
#contact_form_panel .form_row
{
margin:4px 0;
}
#contact_form_panel textarea
{
width:100%;
}
#moreinfo
{
clear:both;
}

-->
</style>

<?php echo $_HEAD['close_tag'] . iEOL; ?>

<!-- *** END DOCUMENT HEAD *** -->


<body>

<!-- PAGE DIV -->
<div id="page">

<!-- MASTHEAD -->
<div id="masthead">
<h1><?php echo $page_title; ?></h1>
<h4>subtitle</h4>
</div>

<!-- CONTENT -->
<div id="content">

<table id="content_table"><tr>

<!-- NAVBAR -->
<td id="content_left">
<?php echo $_HTML['menubar']; ?>
</td>

<!-- INSERT -->
<td id="content_right">
<?php include_once($_iPATH['content_file']); ?>
</td>

</tr></table>

</div>
<!-- end CONTENT div -->

<!-- FOOTER -->
<?php
// calculate page load time
$tx2 = microtime();
$tx_in_s = number_format(((substr($tx2,0,9)) + (substr($tx2,-10)) - (substr($tx1,0,9)) - (substr($tx1,-10))),4);
?>

<div id="footer">
last update : <?php echo date("F j, Y", filemtime(__FILE__)); ?><br />
page loaded in <?php echo $tx_in_s; ?> s
</div>

</div> <!-- end PAGE div-->

<?php

/*__end VIEWER__________________________________*/



/* 5. DIAGNOSTICS *******************************/

// SCRIPT TIMER
# stage_timer('end page');

// SESSION DUMP
# session_dump();

/*______________________________________________*/

?>

<!-- Close HTML -->
</body>
</html>

<?php

/* 6. POSTSCRIPTS *******************************/

// Flush All
while (ob_get_level() > 0)
{
ob_end_flush();
}
flush();
echo '<!-- Buffer Dumped at ' . date("m/d/Y G:i:s") . ' -->';

// Pseudo-Daemon
#log_session();

/*______________________________________________*/

?>


keywords: PHP, template, MVC, framework

P.S. Why the hell is Blogger requiring me to input the word verification? That is, how is this site being confused with a splog site?
Why didn't you use some simple classes?