From b08fd9f34745749fa1dc245c071b0630f6581cf7 Mon Sep 17 00:00:00 2001
From: Matthieu Guffroy <mattgu74@gmail.com>
Date: Thu, 12 Jun 2014 01:41:35 +0200
Subject: [PATCH] Implement mainController

---
 index.php      | 21 ++++++++++++++++-----
 view/index.php |  5 +++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/index.php b/index.php
index 1cd7cd8..ebb0c76 100644
--- a/index.php
+++ b/index.php
@@ -2,14 +2,25 @@
     // This file is the main controller
     include 'template/header.php';
 
-    // TODO: Handle url to detect wich controller to call
+    // Handle url
+    $url = explode("/", $_SERVER['PHP_SELF']);
+    if(isset($url[3])) { 
+        $page = $url[3]; 
+    } else { 
+        $page = "index"; 
+    }
+    if(isset($url[4])) { 
+        $action = $url[4]; 
+    } else { 
+        $action = ""; 
+    }
+    if(!file_exists('controller/'.$page.'.php')) { $page = "404"; }
 
     // Show the menu, the previous part have set wich page we are on to set the "active" class in menu
     include 'template/menu.php';
 
-    // TODO: Call the correct controller
-    include 'controller/index.php';
+    // Call the correct controller
+    include 'controller/'.$page.'.php';
 
     // Show the footer
-    include 'template/footer.php';
-?>
+    include 'template/footer.php';
\ No newline at end of file
diff --git a/view/index.php b/view/index.php
index b439f75..4c6222c 100644
--- a/view/index.php
+++ b/view/index.php
@@ -3,6 +3,11 @@
       <div class="page-header">
         <h1>Sticky footer with fixed navbar</h1>
       </div>
+      <pre>
+      	<?php print_r($url); ?>
+      <pre>
+      	<?php print_r($_SERVER); ?>
+      </pre>
       <p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
       <p>Back to <a href="../sticky-footer">the default sticky footer</a> minus the navbar.</p>
     </div>
\ No newline at end of file
-- 
GitLab