# Routes

The routes can be managed in a traditional way where the last part of the route can be the controller or a function of the controller.

The following route:


Would load the post.php file inside the blog folder in the controller path.

So, the following route:


Will call the sayHi function in the post controller class if it exists.


Routes can also be managed in a cleaner and modern way. In the system/Definitions/Routes.php file you can define routes, its parameters and what to do.

The first parameter is the desired route, the second is the function that will be executed when accessing to the route, the third and optional parameter is the HTTP return code.

The following block of code can be added to Routes.php:

Route::add('main_page', function() {

The same route but with a HTTP 301 response code:

Route::add('main_page', function() {
}, 301);

It will load the home controller when accessing to example.com/mainpage_, obviously you can add more stuff to the function.

The following block of code:

Route::add('main_page/hi', function() {

Will load the sayHi function in the home controller when accessing to example.com/mainpage/hi_

Load a controller directly

You can load a controller in a easier way if you pass a string as the second parameter. It'll be taken as the name of the controller which will be loaded.

Route::add('main_page', 'home');

It will load the home controller when accessing to example.com/mainpage_.

Add with parameters

You can use get parameters in the URL

The following block of code

Route::add('main_page/{name}', function() {
    echo Request::get('name');;

Will take the second part of the route as a get variable which you can get from the common $_GET array using its name as the key, variables should be put between brackets and only be alphanumeric characters.


You can define API routes with the api method.

It is the same than the add function with the difference that this will set the header Content-Type to application/json.

The first parameter is the desired route, the second is the function that will be executed when accessing to the route, the third is the HTTP response code.

Making a simple API GET route that returns a user information based on its id:

Route::api('user/{id}', function () {
    echo DB::run("SELECT * FROM users WHERE user_id = ?", $_GET['id'])->toJson();


Routes can also be blocked using the block function. When blocking a page if anyone tries to gain access to it, they will be redirected to the 404 page.

The following block of code


Will block the access to example.com/mainpage_ only

Block recursively

You can block any sub route using the * symbol


This will block any route that has access to any mainpage/contact_ subdirectory, keep in mind that mainpage/contact_ itself will still be accessible


You can redirect one route to another. When doing it, a 301 HTTP response code will be returned.

Route::redirect('page1', 'page2');

With this the route of page1 will redirect to page2, you can specify an HTTP response code if you want.

Route::redirect('page1', 'page2', 200);

Will do the same but returning a 200 HTTP response code.


The Route class has some useful methods that you can use.


Returns true if a view exists, false otherwise.

//Will return true if the home route exists


Returns all the available routes.



Returns all the available redirections.



Returns all the blocked routes.


Keep in mind that all these get methods returns an associative array with the results.