<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
    <added>
      <filename>controllers/admin/projects_controller.php</filename>
    </added>
    <added>
      <filename>views/admin/projects/edit.php</filename>
    </added>
    <added>
      <filename>views/admin/projects/index.php</filename>
    </added>
    <added>
      <filename>views/friends/friend.php</filename>
    </added>
    <added>
      <filename>views/home/index.php</filename>
    </added>
    <added>
      <filename>views/projects/index.php</filename>
    </added>
    <added>
      <filename>views/projects/item.php</filename>
    </added>
    <added>
      <filename>views/projects/project.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -11,7 +11,7 @@ $GLOBALS['routes'] = array(
 	'/hello-world/[action]' =&gt; 'hello_world',
 
 	//Requests to /projects will go to the projects controller inside the admin folder in controllers
-	'/admin/projects' =&gt; 'admin/projects',	
+	'/admin/projects/[action]' =&gt; 'admin/projects',	
 	
 	//Requests to /non-existent-controller will include /views/non_existent_controller.php, as the controller itself doesn't exist
 	'/non-existent-controller' =&gt; 'non_existent_controller',	</diff>
      <filename>config/routes.php</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,5 @@ class controller {
 	function __construct() {
 		//Why not add authorisation checks in here, then all controllers can inherit
 	}
-	
-	function index() {
-		echo &quot;No index method defined for this controller&quot;;
-	}
 
 }
\ No newline at end of file</diff>
      <filename>controllers/controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ class friends_controller extends controller {
 		$user = new user($this-&gt;parameters['user']);
 		$other_user = new user($this-&gt;parameters['friend']);
 		$friend = new friend($user-&gt;username,$other_user-&gt;username);
-		require_once(&quot;views/friend.php&quot;);
+		require_once(&quot;views/friends/friend.php&quot;);
 		exit;
 	}
 </diff>
      <filename>controllers/friends_controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,4 @@
 
 class home_controller extends controller {
 	
-
-	// GET /
-	function index() {
-		echo &quot;This is the home page&quot;;
-	}
-
 }
\ No newline at end of file</diff>
      <filename>controllers/home_controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -8,13 +8,13 @@ class projects_controller extends controller {
 
 	// GET /projects
 	function index() {
-		require_once(&quot;views/projects.php&quot;);
+		require_once(&quot;views/projects/index.php&quot;);
 		exit;
 	}
 	
 	// GET /projects/1234
 	function view($project) {
-		require_once(&quot;views/project.php&quot;);
+		require_once(&quot;views/projects/project.php&quot;);
 		exit;
 	}
 	
@@ -28,7 +28,7 @@ class projects_controller extends controller {
 
 	// GET //projects/1234/items/567
 	function view_item($project,$item) {
-		require_once(&quot;views/item.php&quot;);
+		require_once(&quot;views/projects/item.php&quot;);
 		exit;
 	}
 </diff>
      <filename>controllers/projects_controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -14,65 +14,62 @@ class router {
 		while (substr($path, -1) == '/') {
 			$path = mb_substr($path,0,(mb_strlen($path)-1));
 		}
-		$pathComponents = explode('/', $path);
+		$path_components = explode('/', $path);
 
 
 		//default actions are called 'index'
 		$action = &quot;index&quot;;
 		
 		//Handle home page requests
-		if (count($pathComponents) == 1) {
-			router::performControllerAction(&quot;home&quot;,$action,array(),array());
+		if (count($path_components) == 1) {
+			router::perform_controller_action(&quot;home&quot;,$action,array(),array());
 		}
-		
+	
 		
 		//Loop through all the routes we defined in route.php, and try to find one that matches our request
 		foreach ($GLOBALS['routes'] as $route =&gt; $controller) {
-			$routeComponents = explode(&quot;/&quot;,$route);
+			$route_components = explode(&quot;/&quot;,$route);
 			$action = &quot;index&quot;;
 			$i=0;
 			$objects = array();
 			$goodRoute = true;
-			$pathComponents = array_pad($pathComponents, count($routeComponents), '');
+			$path_components = array_pad($path_components, count($route_components), '');
 			$parameters = array();
 	
 			//Handle routes that call a specific action
-			$controllerActionArray = explode(&quot;:&quot;,$controller);
-			$controller = $controllerActionArray[0];
-			if (count($controllerActionArray) == 2) {
-				$action = $controllerActionArray[1];
+			$controller_action_array = explode(&quot;:&quot;,$controller);
+			$controller = $controller_action_array[0];
+			if (count($controller_action_array) == 2) {
+				$action = $controller_action_array[1];
 			}
 	
 			//Loop through each component of this route until we find a part that doesn't match, or we run out of url
-			foreach ($routeComponents as $routeComponent) {
+			foreach ($route_components as $route_component) {
 				
 		
 				//This part of the route is a named parameter
-				if (substr($routeComponent,0,1) == &quot;:&quot;) {
-					$parameters[substr($routeComponent,1)] = $pathComponents[$i];
+				if (substr($route_component,0,1) == &quot;:&quot;) {
+					$parameters[substr($route_component,1)] = $path_components[$i];
 		
 		
 				//This part of the route is an action for a controller
-				} elseif ($routeComponent == &quot;[action]&quot;) {
-					if ($pathComponents[$i] != &quot;&quot;) {
-						$action = $pathComponents[$i];
+				} elseif ($route_component == &quot;[action]&quot;) {
+					if ($path_components[$i] != &quot;&quot;) {
+						$action = str_replace(&quot;-&quot;,&quot;_&quot;,$path_components[$i]);
 					}
 					
 				//This part of the route will require that we create an object
-				} elseif (substr($routeComponent,0,1) == &quot;(&quot; &amp;&amp; substr($routeComponent,-1,1) == &quot;)&quot;) {
-					$reflectionObj = new ReflectionClass(substr($routeComponent,1,strlen($routeComponent)-2)); 
-					$object = $reflectionObj-&gt;newInstanceArgs(array($pathComponents[$i]));
+				} elseif (substr($route_component,0,1) == &quot;(&quot; &amp;&amp; substr($route_component,-1,1) == &quot;)&quot;) {
+					$reflection_obj = new ReflectionClass(substr($route_component,1,strlen($route_component)-2)); 
+					$object = $reflection_obj-&gt;newInstanceArgs(array($path_components[$i]));
 					
-					//If we couldn't make an object and this part of the url isn't empty, we probably wanted a different route
-					if (!$object-&gt;is_valid &amp;&amp; $pathComponents[$i] != &quot;&quot;) {
-						$goodRoute = false;
-					}
+
 					$objects[] = $object;
 					
 
 				//Part of the url that isn't an action or an object didn't match, this definitely isn't the right route
-				} elseif ($routeComponent != $pathComponents[$i]) {
-					#echo &quot;Bad match $routeComponent != &quot;.$pathComponents[$i].&quot;&lt;br /&gt;&quot;;
+				} elseif ($route_component != $path_components[$i] &amp;&amp; str_replace(&quot;-&quot;,&quot;_&quot;,$route_component) != $path_components[$i]) {
+					//echo &quot;Bad match: &quot;.str_replace(&quot;-&quot;,&quot;_&quot;,$route_component).&quot; != &quot;.$path_components[$i].&quot;&lt;br /&gt;&quot;;
 					$goodRoute = false;
 					break;
 				}
@@ -80,8 +77,9 @@ class router {
 			}
 			
 			//This route is a match for our request, let's get the controller working on it
-			if ($goodRoute &amp;&amp; ($i &gt;= count($pathComponents) || $pathComponents[$i] == &quot;&quot;)) {
-				router::performControllerAction($controller,$action,$objects,$parameters);
+			if ($goodRoute &amp;&amp; ($i &gt;= count($path_components) || $path_components[$i] == &quot;&quot;)) {
+
+				router::perform_controller_action($controller,$action,$objects,$parameters);
 			}
 		}
 		
@@ -90,39 +88,51 @@ class router {
 	}
 	
 	//Look for a controller file matching the request, and failing that, a view
-	static function performControllerAction($path,$action,$objects,$parameters) {
+	static function perform_controller_action($class_path,$action,$objects,$parameters) {
 		
-		//Nice urls: treat /hello-world the same as /hello_world
-		$action = str_replace(&quot;-&quot;,&quot;_&quot;,$action);
+		//We treat 'new' the same as 'edit', since they generally contain a lot of the same code
+		if ($action == &quot;new&quot;) {
+			$action = &quot;edit&quot;;
+		}
 		
-	
-		//First, let's look for a controller
-		$controllerPath = SITE_PATH.&quot;/controllers/&quot;.$path.&quot;_controller.php&quot;;
+		//Let's look for a controller
+		$controller_path = SITE_PATH.&quot;/controllers/&quot;.$class_path.&quot;_controller.php&quot;;
 
 
-		if (file_exists($controllerPath)) {
-			require_once($controllerPath);
-			if ($action == &quot;new&quot;) {
-				$action = &quot;edit&quot;;
-			}
-			$class = explode(&quot;/&quot;,$path);
-			$class = $class[count($class)-1].&quot;_controller&quot;;
-			if (!method_exists($class,$action)) {
-				fatal_error(&quot;$class does not respond to $action&quot;);
+		if (file_exists($controller_path)) {
+			require_once($controller_path);
+			
+			$class_path_components = explode(&quot;/&quot;,$class_path);
+			$class = $class_path_components[count($class_path_components)-1];
+			$controller_class = $class.&quot;_controller&quot;;
+			if (!method_exists($controller_class,$action)) {
+				if (router::render_view($class_path,$action)) {
+					exit;
+				} else {
+					fatal_error(&quot;$controller_class does not respond to $action&quot;);
+				}
 			}
 			
-			$controller = new $class();
+			$controller = new $controller_class();
 			$controller-&gt;parameters = $parameters;
 			call_user_func_array(array($controller,$action),$objects);
 			exit;
 		}
 		
 		//If no controller was found, we'll look for a view
-		$viewPath = SITE_PATH.&quot;/views/&quot;.$path.&quot;.php&quot;;
-		if (file_exists($viewPath)) {
-			require_once($viewPath);
+		if (router::render_view($class_path,$action)) {
 			exit;
 		}
 	}
-
+	
+	static function render_view($class_path,$action) {
+		$view_path = SITE_PATH.&quot;/views/$class_path/&quot;.$action.&quot;.php&quot;;
+		if (file_exists($view_path)) {
+			$controller = new controller();
+			require_once($view_path);
+			return true;
+		}
+		return false;
+	}
 }
+</diff>
      <filename>helpers/router.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,5 +13,8 @@ class project extends model {
 			$this-&gt;is_valid = true;
 		}
 	}
+	
+	function delete() {
+	}
 
 }
\ No newline at end of file</diff>
      <filename>models/project.php</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>views/friend.php</filename>
    </removed>
    <removed>
      <filename>views/item.php</filename>
    </removed>
    <removed>
      <filename>views/project.php</filename>
    </removed>
    <removed>
      <filename>views/projects.php</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>89c858cbb53aad196b9764f28fb034b0ec276dd9</id>
    </parent>
  </parents>
  <author>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </author>
  <url>http://github.com/pokeb/php-mvc-router/commit/7da53852665d79afb90b4441d6b3763a46e40bb5</url>
  <id>7da53852665d79afb90b4441d6b3763a46e40bb5</id>
  <committed-date>2008-08-25T04:31:06-07:00</committed-date>
  <authored-date>2008-08-25T04:31:06-07:00</authored-date>
  <message>Reorganise system for parsing views:
* Views are now stored in folders named after their controller, to better deal with larger sites
* When using the [action] syntax, a matching view will be rendered when no action in the controller exists

Also:
* More reliable hyphen to underscore conversion
* Index page now shows a list of links that match those in the example routes.php
* Variable naming convention changed to use underscores rather than lowerCamelCase (yep, I've spent too much time  with rails..)
* Misc bug fixes - all the examples should work now
* Added per-site config files to .gitignore</message>
  <tree>55926240db65ac4591dbb31b64327d8bb8c416f0</tree>
  <committer>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </committer>
</commit>
