Errors and exceptions handling, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@122 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -20,12 +20,9 @@ abstract class Action
|
||||
|
||||
protected function extractParams()
|
||||
{
|
||||
$params = FrontController::getInstance()->getRouter()->getRoute()->getParams();
|
||||
if ($params) {
|
||||
foreach ($params as $name => $value) {
|
||||
if (is_string($name)) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
foreach (Env::getParam() as $name => $value) {
|
||||
if (is_string($name)) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ class ErrorAction extends ViewAction
|
||||
public function __construct($exception)
|
||||
{
|
||||
$this->exception = $exception;
|
||||
$this->view = FrontController::getInstance()->getView();
|
||||
$this->execute();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute()
|
||||
|
@ -100,12 +100,18 @@ class FrontController
|
||||
$request = Env::getRequestUri();
|
||||
$route = $this->getRouter()->route($request);
|
||||
if (!$route) {
|
||||
throw new Error404Exception('Route "' . $request . '" not found');
|
||||
throw new Error404Exception('Route for "' . $request . '" not found');
|
||||
}
|
||||
|
||||
$action_class = $route->getAction();
|
||||
if (!class_exists($action_class)) {
|
||||
throw new GeneralException('Action class "' . $action_class . '" not found.');
|
||||
}
|
||||
$action = new $action_class();
|
||||
$layout_class = $route->getLayout();
|
||||
if (!class_exists($layout_class)) {
|
||||
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
|
||||
}
|
||||
$layout = new $layout_class();
|
||||
return $layout->fetch($action);
|
||||
|
||||
@ -113,7 +119,7 @@ class FrontController
|
||||
if (DEBUG == true) {
|
||||
return ErrorHandler::showDebug($e);
|
||||
}
|
||||
$layout = new DefaultLayout();
|
||||
$layout = new ErrorLayout();
|
||||
return $layout->fetch(new ErrorAction($e));
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Router
|
||||
|
||||
public function add($name, $route, $action, $params = null, $layout = null)
|
||||
{
|
||||
if (! $layout) {
|
||||
if (!$layout) {
|
||||
$layout = $this->default_layout;
|
||||
}
|
||||
$this->routes[$name] = new Route($route, $action, $params, $layout);
|
||||
@ -37,8 +37,9 @@ class Router
|
||||
|
||||
foreach ($this->routes as $name => $route) {
|
||||
if ($route->match($req)) {
|
||||
$this->route_name = $route;
|
||||
$this->route_name = $name;
|
||||
$this->route = $route;
|
||||
Env::setParams($route->getParams());
|
||||
return $this->route;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user