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.

Accessing Child Modules

Trongate provides multiple ways to access and utilize child modules within your application.

URL Routing

To access a child module via URL, use the following format:

Example #1

The code sample below demonstrates how to access the 'display' method of an 'accessories' child module within a 'cars' parent module:


Creating Links

Example #2

The code sample below demonstrates how to use the Trongate anchor() function to create links to child module methods:


Loading Child Modules Programmatically

To load a child module within a controller or another module:

Example #3

This example demonstrates how to load and use a child module named 'product_reviews' within a parent module 'shop'. We'll load the child module and then call its 'get_latest_reviews' method:

In this example, the 'product_reviews' child module is loaded using:

Thereafter, the child module's methods can be accessed using syntax of the following form:

In the line of code above, method_name would be replaced with a meaningful and valid method name. The method name would reference a method within the product_reviews module.

The example shown above fetches reviews, passing in the $product_id as an argument:

For a more robust and modern coding style, consider using access modifiers, doc blocks, type hinting and return types. For example:

In the code sample above we have a type hinting value set to 'mixed'. This is because the display_product() method is attempting to read the $product_id from the third segment of the URL. The expectation is that the $product_id will be an integer. However, if it's not then certainly don't want the code to break! For this reason, we set the type to an integer with:

The following line of code would have achieved the same effect (making sure $product_id is an integer:

×