Update Router
This commit is contained in:
parent
5de88986ed
commit
be96e2c6af
@ -44,6 +44,31 @@ class Router extends RoutingBase {
|
|||||||
$this->request = $container->get('request');
|
$this->request = $container->get('request');
|
||||||
|
|
||||||
$this->output_routes = $this->_setup_routes();
|
$this->output_routes = $this->_setup_routes();
|
||||||
|
$this->generate_convention_routes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate routes based on controller methods
|
||||||
|
*
|
||||||
|
* @return [type] [description]
|
||||||
|
*/
|
||||||
|
protected function generate_convention_routes()
|
||||||
|
{
|
||||||
|
$this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}')
|
||||||
|
->setValues([
|
||||||
|
'controller' => $this->routes['convention']['default_controller'],
|
||||||
|
'action' => $this->routes['convention']['default_method'],
|
||||||
|
])->setTokens([
|
||||||
|
'type' => '[a-z_]+',
|
||||||
|
'view' => '[a-z_]+'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->output_routes[] = $this->router->add('generic', '{/controller,action,view}')
|
||||||
|
->setValues([
|
||||||
|
'controller' => $this->routes['convention']['default_controller'],
|
||||||
|
'action' => $this->routes['convention']['default_method'],
|
||||||
|
'view' => '',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,13 +126,20 @@ class Router extends RoutingBase {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list($controller_name, $action_method) = $route->params['action'];
|
$controller_name = $route->params['controller'];
|
||||||
|
$action_method = $route->params['action'];
|
||||||
|
|
||||||
if (is_null($controller_name))
|
if (is_null($controller_name))
|
||||||
{
|
{
|
||||||
throw new \LogicException("Missing controller");
|
throw new \LogicException("Missing controller");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strpos($controller_name, '\\') === FALSE)
|
||||||
|
{
|
||||||
|
$map = $this->get_controller_list();
|
||||||
|
$controller_name = $map[$controller_name];
|
||||||
|
}
|
||||||
|
|
||||||
$params = (isset($route->params['params'])) ? $route->params['params'] : [];
|
$params = (isset($route->params['params'])) ? $route->params['params'] : [];
|
||||||
|
|
||||||
if ( ! empty($route->tokens))
|
if ( ! empty($route->tokens))
|
||||||
@ -210,7 +242,7 @@ class Router extends RoutingBase {
|
|||||||
$controller_class = $controller_map[$route_type];
|
$controller_class = $controller_map[$route_type];
|
||||||
|
|
||||||
// Prepend the controller to the route parameters
|
// Prepend the controller to the route parameters
|
||||||
array_unshift($route['action'], $controller_class);
|
$route['controller'] = $controller_class;
|
||||||
|
|
||||||
// Select the appropriate router method based on the http verb
|
// Select the appropriate router method based on the http verb
|
||||||
$add = (array_key_exists('verb', $route))
|
$add = (array_key_exists('verb', $route))
|
||||||
|
Loading…
Reference in New Issue
Block a user