Trongate PHP Framework Docs
Introduction
Quick Start
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
Security
Tips And Best Practices

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
1stmembersModule folder + controller
2ndprofileMethod to run
3rd+88Available via function

So this URL runs:

PHP
<?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 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

  1. Module folders: lowercase (or snake_case)
  2. Controller files: Firstlettercap (e.g., Members.php)
  3. Methods: lowercase (or snake_case)
  4. 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

  • /productsProducts->index()
  • /products/manageProducts->manage()
  • /products/display/42Products->display() + segment(3, 'int') returns 42

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page