Header Small Ahoy!

Homepage Routing

Routing plays a crucial role in defining the code that gets called whenever a user accesses the homepage of a website. Trongate's routing system maps the root URL, typically the homepage, to a specific module and controller that serves as the entry point for the application.

In Trongate, routing to the homepage is configured through settings, defined within the config.php file. This configuration file is the main configuration file for Trongate and it is located within the 'config' directory. These settings specify which module, controller, and method are invoked when the homepage (represented, in code, by the BASE_URL constant) receives an HTTP GET request.

Default Homepage Routing Configuration

The code sample below (taken from config.php) shows the default constants that are used when a website visitor acccesses the homepage of a Trongate application:


define('DEFAULT_MODULE', 'welcome');
define('DEFAULT_CONTROLLER', 'Welcome');
define('DEFAULT_METHOD', 'index');

Each constant has a specific role in the application's entry point configuration:

With Trongate's default configuration settings, accessing the BASE_URL triggers the 'welcome' module, loading a 'Welcome' controller file that is located inside the 'welcome' module. Thereafter, an 'index' method - which is part of the containing 'Welcome' class - is immediately invoked.

Customizing Homepage Routing

To customize homepage routing, modify the respective constants in the config.php file as required. For example:


define('DEFAULT_MODULE', 'dashboard');
define('DEFAULT_CONTROLLER', 'Dashboard');
define('DEFAULT_METHOD', 'index');

The adjustments shown above would ensure that visiting the BASE_URL now loads the 'index' method within the 'Dashboard' controller of a hypothetical 'dashboard' module, effectively altering the initial user experience.

It's important to verify that the specified module, controller, and method are correctly implemented to prevent errors during homepage access.