mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
added support for organizing routes in a routes directory.
This commit is contained in:
parent
285cdcc8f2
commit
d2a74750c9
@ -30,7 +30,41 @@ class Router {
|
||||
// --------------------------------------------------------------
|
||||
$uri = ($uri != '/') ? '/'.$uri : $uri;
|
||||
|
||||
static::$routes = require APP_PATH.'routes'.EXT;
|
||||
// --------------------------------------------------------------
|
||||
// If a route directory is being used, load the route file
|
||||
// corresponding to the first segment of the URI.
|
||||
// --------------------------------------------------------------
|
||||
if (is_dir(APP_PATH.'routes'))
|
||||
{
|
||||
if ($uri == '/')
|
||||
{
|
||||
if ( ! file_exists(APP_PATH.'routes/home'.EXT))
|
||||
{
|
||||
throw new \Exception("A [home] route file is required when using a route directory.");
|
||||
}
|
||||
|
||||
static::$routes = require APP_PATH.'routes/home'.EXT;
|
||||
}
|
||||
else
|
||||
{
|
||||
$segments = explode('/', trim($uri, '/'));
|
||||
|
||||
if ( ! file_exists(APP_PATH.'routes/'.$segments[0].EXT))
|
||||
{
|
||||
throw new \Exception("No route file defined for routes beginning with [".$segments[0]."]");
|
||||
}
|
||||
|
||||
static::$routes = require APP_PATH.'routes/'.$segments[0].EXT;
|
||||
}
|
||||
}
|
||||
// --------------------------------------------------------------
|
||||
// If no route directory is being used, we can simply load the
|
||||
// routes file from the application directory.
|
||||
// --------------------------------------------------------------
|
||||
else
|
||||
{
|
||||
static::$routes = require APP_PATH.'routes'.EXT;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Is there an exact match for the request?
|
||||
|
Loading…
x
Reference in New Issue
Block a user