Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add namespace-based routing. The following would work in your Routing…

….php file:

$ROUTING = array(
    'admin'                          => array( 'namespace' => 'admin', 'action' => 'dashboard', 'method' => 'main' ),
    'admin/:action/:method'          => array( 'namespace' => 'admin', 'action' => 'dashboard', 'method' => 'main' ),
    'admin/:action/:method/*(extra)' => array( 'namespace' => 'admin', 'action' => 'dashboard', 'method' => 'main' ),
);

Neat!
  • Loading branch information...
commit 9d73e4b2be03ef6e2073afd654ea06e93b85c737 1 parent 4d25ca7
timdorr authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 Bee/Dispatch.php
View
19 Bee/Dispatch.php
@@ -273,12 +273,12 @@ private function _dispatch()
$route = $this->_parseRoute();
// Check that controller class exists
- if( !file_exists( 'app/controllers/' . $this->action . '.php' ) )
+ if( !file_exists( 'app/controllers/' . str_replace( '\\', '/', $this->namespace ) . $this->action . '.php' ) )
{
if( $this->throwExceptions() || !file_exists( 'app/views/404.tpl' ) )
{
header( 'HTTP/1.1 404 Not Found' );
- throw new Bee_Dispatch_Exception( "Controller ($this->action) not found" );
+ throw new Bee_Dispatch_Exception( "Controller ($this->namespace\\$this->action) not found" );
}
else
{
@@ -289,8 +289,8 @@ private function _dispatch()
}
// Instantiate the action controller
- require_once 'controllers/' . $this->action . '.php';
- $action = ucfirst( $this->action ) . '_Controller';
+ require_once 'controllers/' . str_replace( '\\', '/', $this->namespace ) . $this->action . '.php';
+ $action = '\\' . ucfirst( $this->namespace ) . ucfirst( $this->action ) . '_Controller';
$this->controller = $controller = new $action( array_merge( $this->config, array( 'baseURL' => $this->_baseURL, 'route' => $route ) ) );
// If a method wasn't defined in the URI, grab the default from the controller
@@ -314,7 +314,7 @@ private function _dispatch()
$controller->completeDispatch();
// Display back to the browser
- Bee_Display::display( $this->action . '/' . $this->method, get_object_vars( $controller ) );
+ Bee_Display::display( str_replace( '\\', '/', $this->namespace ) . $this->action . '/' . $this->method, get_object_vars( $controller ) );
}
/**
@@ -337,10 +337,17 @@ private function _parseRoute()
$m->connect( $pattern, $mapping );
// Connect our default route
- $m->connect( ':action/:method/*(extra)', array( 'action' => 'index', 'method' => 'main', 'extra' => null ) );
+ $m->connect( ':action/:method/*(extra)', array( 'namespace' => '', 'action' => 'index', 'method' => 'main', 'extra' => null ) );
// Get our route and hook everything up
$route = $m->match( $_SERVER['REQUEST_URI'] );
+
+ // An empty namespace doesn't have a trailing slash
+ if( !empty( $route['namespace'] ) )
+ $this->namespace = $route['namespace'] . '\\';
+ else
+ $this->namespace = '';
+
$this->action = $route['action'];
$this->method = $route['method'];
Please sign in to comment.
Something went wrong with that request. Please try again.