Created
June 10, 2012 20:19
-
-
Save tchalvak/2907199 to your computer and use it in GitHub Desktop.
Example of code for the belts.php page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(CORE.'core.php') // Includes core systems, a templating engine, any mvc framework, etc. | |
/* ================== Intro =========================================== | |
Ok, so this is an example like many of our current scripts, which it should be obvious need a lot of refactoring to be more useful. | |
This should be split into (at least) two php scripts, one that's an html template, and one that includes all the php logic. | |
You can pretend that there's a template engine and/or MVC system of your choice available to use and just show me whatever kind of templating syntax | |
or MVC approach you're familiar with. | |
Ideally this would mostly be abstracted into more reusable functionality for headers, footers, and the template section would only | |
contain the appropriate body content for rendering by a template engine, and the php section would only contain script-specific processing. | |
*/ | |
session_start(); | |
// Get the data to be used on the page via custom sql, not really the best way. | |
$belt_brands = query("SELECT brands.Code, brands.Name as BrandName, brands.DescrShort, brands.LogoURL FROM types, items, brands WHERE types.Name LIKE '%Belt%' AND types.TypeId = items.TypeId AND items.BrandCode = brands.Code AND items.flagStatus != 'U' GROUP BY brands.Code ORDER BY brands.Name"); | |
// Set page-specific qualities. | |
$Title = 'Belts'; | |
include('heading.php'); // Top heading of a page, handles the title, metadata, global css files, global js files, etc. Not the best approach, could use abstraction to MVC or a template rendering fucntion. | |
?> | |
<?php | |
// functions that include everything except the main content, including top navigation, logo, leftnav, breadcrumbs, etc. | |
display_top_of_page($breadcrumbs=null, $dynamic_breadcrumbs=null, $page_class='belts-page'); // includes leftnav, the start of the central column td that has a background color of #ffffff, and possibly a breadcrumb trail, END. | |
// ================================= Main HTML ======================================================= | |
//Start of the core html output that should be transformed into some template engine's syntax and separated from the php logic. | |
// Turn this into a template engine syntax of your choice. | |
?> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-left:5px"> | |
<tr><td> | |
<h1 class='fancy-nothing-font page-title'>Belts</h1></td></tr> | |
<tr> | |
<td>Click on any of the links below to shop our belt collections by brand or browse <a href="catalog.php?TypeId=1">All Premium Belt Collections</a>.</td> | |
</tr> | |
<tr> | |
<td> </td> | |
</tr> | |
</table> | |
<?php | |
foreach ($belt_brands as $belt_brand) { | |
?> | |
<div class='belt-brand' style='margin-top:0;margin-bottom:.3em;'> | |
<h3 style="padding:5px;background:#99a4de; border-top:1px solid #000000; border-bottom:1px solid #000000;font-weight:bold" class='belt-brand-name brand-name'> | |
<?php h($belt_brand['BrandName']); ?> | |
</h3> | |
<div class='brand-desc' style='padding:5px'> | |
<a href="catalog.php?TypeId=1&TypeBrandCode=<?php h($belt_brand['Code']); ?>"> | |
<img src="assets/belt-<?php h($belt_brand['LogoURL']); ?>" | |
width='150' border="0" align="right" style="padding:5px; margin-left:5px; border:1px solid #cccccc" | |
alt="<?php h($belt_brand['BrandName']); ?> Belts" | |
title="<?php h($belt_brand['BrandName']); ?> Belts"> | |
</a> | |
<div class='short-brand-description'> | |
<?php echo $belt_brand['DescrShort']; // Uses unescaped html, sadly ?> | |
</div> | |
</div> | |
<div class='shop-belts' style='width:100%;text-align:center;font-size:1.1em;font-weight:bold;clear:both;'> | |
[ <a class='shop-belts-link' href="catalog.php?TypeId=1&TypeBrandCode=<?php echo $belt_brand['Code']; ?>"> | |
Shop <?php h($belt_brand['BrandName']); ?> Belts</a> ] | |
</div> | |
</div> <!-- End of a belt brand --> | |
<?php } // End of belt_brands loop | |
?> | |
<?php | |
// End of the core stuff that a page will display, and start of generic wrappers. | |
display_bottom_of_page(); // handles bottom of the containing wrapper, a rightnav, and everything before the footer. | |
?> | |
<?php | |
include('includes/footer.php'); // Site Footer, google analytics, etc. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment