What are the benefits of utilizing laravel's "Routes" opposed to having a custom bootstrap that splits the URL based off '/' and then the bootstrap can automatically load the controller and pass functions and parameters. Here is an example of a custom Bootstrap I have used. I am new to laravel and just trying to conceptually understand as there are several terms/features I am not used to.
class Bootstrap
{
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
//If url is empty load homepage
if(empty($url[0]))
{
$url[0] = 'index';
$page = 'index';
require 'controllers/index_controller.php';
$controller = new Index();
$controller->renderView($url[0], $page);
return false;
}
//If url isn't empty is the controller available
$file = './controllers/' . $url[0] . '_controller.php';
if (file_exists($file))
{
require $file;
}
else
{
//Controller not found
require 'controllers/error.php';
$controller = new Error();
return false;
}
//if controller is found create new object
$controller = new $url[0];
$controller->loadModel($url[0]);
if (isset($url[4]))
{
$controller->{$url[1]}($url[2], $url[3], $url[4]);
return false;
}
if (isset($url[3]))
{
$controller->{$url[1]}($url[2], $url[3]);
return false;
}
//If parameters are specified pass the method and parameters to the controller
if (isset($url[2]))
{
$controller->{$url[1]}($url[2]);
return false;
}
//otherwise just pass the method call to the controller
else
{
if (isset($url[1]))
{
$controller->{$url[1]}();
return false;
}
else
{
//if no method is called just display default view for the controller
$controller->renderView($url[0], 'index');
}
}
}
}
Possible security vulnerability by accessing controllers directly and displaying methods?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community