Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Automatic URL Routing
Trongate makes routing effortless. Just type the URL, and the framework figures out which code to run - no route registration, no caching, no extra fuss.
How URL Segments Work
Example URL:
https://example.com/members/profile/88
Trongate breaks it into segments:
| Segment | Example | Purpose |
|---|---|---|
| 1st | members | Module folder + controller |
| 2nd | profile | Method to run |
| 3rd+ | 88 | Available via segment() function |
So this URL runs:
<?php
class Members extends Trongate {
function profile() {
$user_id = segment(3, 'int'); // Fetch segment 3 as integer
echo "User profile loaded. No config required. PHP is good.";
}
}
Changed in v2: URL segments are no longer auto-passed as method parameters.
Use segment() to fetch variables from the URL explicitly. This follows the same principle that guided PHP's removal of register_globals:
- Explicit is safer than implicit - developers must deliberately read data from the URL, making trust boundaries clear and reducing accidental misuse.
- Improved security posture - explicit fetching creates a natural checkpoint for validation and sanitization before data is used.
- Greater code clarity - when reading a controller, it is immediately obvious where external input originates.
- Less framework magic - removing automatic parameter injection aligns Trongate more closely with native PHP behavior.
- Modern strictness - explicit data access reflects the broader trend in modern PHP and web development toward stricter, more predictable code.
The Rules
- Module folders:
lowercase(orsnake_case) - Controller files:
Firstlettercap(e.g.,Members.php) - Methods:
lowercase(orsnake_case) - No method? → automatically runs
index()
Note: Custom routes in config/custom_routing.php override automatic routing like a polite bouncer: "Sorry mate, VIP list wins."
Quick Examples
/products→Products->index()/products/manage→Products->manage()/products/display/42→Products->display()+segment(3, 'int')returns42