Trongate Docs
switch to dark modeswitch to dark mode
The Structure Of A Controller

The Structure Of A Controller

Below is an example of a basic Trongate controller file called 'Dice'.

class Dice extends Trongate {

    function roll() {
        $number = rand(1, 6);
        echo $number;


The controller would be named 'Dice.php' and would exist inside a module named 'dice'.

As you can see, the Dice controller contains a PHP class that extends the (inbuilt) 'Trongate' class. The Trongate class is a class inside the 'engine' folder.  Extending the Trongate class gives the Dice controller the power to access all of Trongate's hidden goodies like; form validation, a URL helper and much more.

The Dice controller contains one method (a function inside a class).  The name of the method is 'roll'.

The roll() method can be invoked by going to your main website URL followed by 'dice/roll'.  For example:

The roll method generates a random number between one and six - using PHP's inbuilt rand() function.  Then, the random number that has been generated is displayed on the screen.

sample output

Remember to:

  • Always start your controller file name with a capital letter
  • Always start your controller class names with a capital letter
  • Always give your (main) controller class the same name as the module where it resides (keeping in mind that the module name can be all lowercase)


    If you have a question or a comment relating to anything you've see here, please goto the Help Bar.