The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

Loading Modules From Controllers

Within the Trongate framework, there are two primary methods for a module to load another module.

The first method involves loading a module from within a controller file, while the second involves loading a module from a view file. This section focuses on loading a module from a controller file.

To load a module from a controller, use the following syntax:

As illustrated, only two lines of code are required to load a method from a different module.

Below is an improved example demonstrating how to call a 'Tax' module to calculate the final price after tax has been applied. This method first loads the 'Tax' module and then invokes its method to add tax to the base price.

Here is a more complex example that involves loading and using three different modules: 'Tax', 'Shipping', and 'Discount'. This method calculates the final price by applying tax, adding shipping costs, and then applying any available discounts.

In the example above:

  • The 'Tax' module's add_tax method is used to add tax to the base price.
  • The 'Shipping' module's add_shipping method calculates and adds the shipping cost to the price with tax.
  • The 'Discount' module's apply_discount method applies any available discounts to the price with shipping.
In this example, the modules are loaded together at the beginning of the method. This approach enhances code readability and maintainability by clearly showing which modules are being used.
×