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.

Optional Additional Parameters

When you are creating your API settings file, there are a range of optional parameters that you can declare for each of your endpoints. The optional parameters are as follows:

Required Fields

  • required_fields: This will be an array of key value pairs, with each pair representing the name and the label for a required field. The code below declares an endpoint that has 'id' as a required field:

If you have a close look at the url_segments, above, you'll notice that the final segment is for 'id' and it's inside curly brackets. When you see this type of pattern in the URL segments, it means that we are expecting a value (in this case, 'id') to be passed in via the URL.

Before Hook

  • beforeHook: The beforeHook parameter can be used to declare a method that should intercept the inbound HTTP request before allowing the request to reach the main endpoint method. Below is an example of an endpoint that has a beforeHook property of '_prep_password'. This endpoint will intercept the inbound HTTP request and run it through a method, on the loaded module, named _prep_password().

The underscore at the start of _prep_password() means that the method is 'protected'. In other words, it cannot be invoked by going to a particular URL.

After Hook

  • afterHook: The afterHook parameter can be used to declare a method that should receive the outbound server response before the response has been served to the end user. Below is an example of an endpoint that has an afterHook property of '_prep_date'. This endpoint will intercept the outbound HTTP response and run it through a method, on the loaded module, named _prep_date(). Our visualisation here would be a scenario where a date/time fetched from a database, such as a Unix timestamp, is to be formatted before being presented to the end user.

Again, you can see that the after hook's method name begins with an underscore. This means that the method is protected.

Before hooks and after hooks are important. Let's explore them in a little more detail!

×