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

Controller Files

Every module gets one controller file. Every controller file contains one PHP class. The boss.

Trongate v2 killed the controllers/ subfolder.

We got rid of this →

And, now we do this →

You're welcome.

Where They Live Now

The text above demonstrates some file and directory locations for a hypothetical 'users' module.

Naming Rules

Thing Rule Example
Module Directory Name lowercase, usually plural luxury_wristwatches
Controller File Name UppercaseFirst, snake_case + .php Luxury_wristwatches.php
Class Name UppercaseFirst, snake_case class Luxury_wristwatches

Bare Minimum Controller

Visit: https://yoursite.com/dice/roll → rolls a die. No config. No YAML. No drama.


Real-World Example: Users

URL → Method magic:

  • /usersindex()
  • /users/profile/42profile(42)

Constructors? Optional.

Don't need one? Don't write one. Need CORS? Read this. Auth? Go nuts:

Never write an empty constructor just to call parent::__construct(). That's 2005. Let it go!

Multiple Classes? Don't.

Want another class? Make a child module. Not another file in the same folder.

Copy. Paste. Works. No require_once hell.

Third-Party? Sure. But Why?

Need Guzzle? Stripe? Fine. Drop Composer in vendor/, autoload it:

But 99% of the time Native PHP wins. Faster. Cleaner. No 3 AM updates.

Namespaces? Only When Forced

Using Packagist? Use their PascalCase namespaces. Otherwise? Snake case everything.

One file. One class. Native PHP rules!

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