Last active
August 29, 2015 14:19
-
-
Save cgsmith/6ef17173539795e98637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<h1>Cart</h1> | |
<?php | |
require 'lib/myLibrary.php'; | |
?> | |
<p>Your cart consists of <?=$_GET['item']. ' for $' . $inventory[$_GET['item']]/100;?></p> |
This file contains hidden or 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
<h1>My Storefront</h1> | |
<?php | |
// Pulling in a library - this would be everywhere | |
require 'lib/myLibrary.php'; | |
// loop over our inventory for the main page | |
// @todo: remove comments - this is a legacy app | |
echo '<ul>'; | |
foreach ($inventory as $item => $price) { | |
echo '<li>' . $item . ' sells for '; | |
echo '$' . $price/100; | |
echo ' <a href="buyit.php?item=' . $item . '">Buy it!</a></li>'; | |
} | |
echo '</ul>'; |
This file contains hidden or 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 | |
// A start towards refactoring | |
require 'classes/router.php'; | |
require 'classes/request.php'; | |
// First step is to configure current routes | |
$routes = [ | |
'/' => 'home.php', | |
'/index.php' => 'home.php', | |
'/buyit.php' => 'buyit.php' | |
]; | |
$request = new request($_REQUEST,$_SERVER); | |
$router = new router($routes, $request); | |
/** | |
* If your router does not match the old route - run through your application | |
* otherwise load up the requires again ;) | |
*/ | |
if (!$router->match()) { | |
$app = new application(); | |
$app->run(); | |
}else { | |
require $router->getOldRoute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment