i have a mini route and mvc system
I have some Classes and methods to centralize some functions inside the app for ex.
Router::route('login')
This method will create a url for the alias matched inside the class Router, the problem comes when the alias doesn't exists, i have this validation
public static function route(string $name) {
$base = self::$_instance->getBasePath();
$alias = self::$_instance->getAliases();
$method = self::$_instance->_request->server('requestMethod');
if( isset($alias[$name]) && $alias[$name][$method] ) {
$route = $alias[$name];
return $base . $route[$method]['uri'];
}
return ("Route {$name} not defined.");
}
So when the route does not exist return Route about not defined, but when I see the browser nothing is shown on screen.
View Code
<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top" style="box-shadow: 0px 0px 2px #ccc;background: #fdfdfd!important;">
<ul class="navbar-nav mr-auto">
<a class="nav-link" href="<?= Router::route('home') ?>">Home</a>
<a class="nav-link" href="<?= Router::route('site.about') ?>">About</a>
<a class="nav-link" href="<?= Router::route('site.contact') ?>">Contact</a>
</ul>
<ul class="navbar-nav ml-auto">
<?php if(Router::has('auth.login')) { ?>
<?php if(Capsule::app()->user()->isAuth()) { ?>
<a class="nav-link" href="/home">Home</a>
<?php } else { ?>
<a class="nav-link" href="<?= Router::route('auth.login') ?>">Login</a>
<a class="nav-link" href="<?= Router::route('auth.register') ?>">Register</a>
<?php } ?>
<?php } ?>
</ul>
</nav>
I Only have the routes: Login, Register and Home, the Contact and About doesnt exists
in the browser i have the links to /Route not defined when i hover the mouse in Contact or About link
but i want that the project flow stop and throw a error like Laravel or Yii Exceptions Something like
Route About not defined
On the whole screen.
Thanks in advance.