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

Utilities Helpers

Utilities helpers are the odds and ends that don't fit anywhere else. Debugging, sorting, IP addresses, file info and view rendering.

Call them whenever:

  • block direct URL access to controller methods
  • debug output in pretty JSON
  • get the client's IP
  • render views inside templates
  • extract filename and extension
  • sort associative arrays
  • sort object arrays
  • detect MX requests

Debug with JSON

The function dumps data in readable JSON format. Perfect for inspecting arrays and objects during development.

Output:

Stop Execution

Pass true as the second argument to kill the script immediately after output:


Get Client IP

The function returns the visitor's IP address.


Render Views

The function loads a view file from a module. Use it inside templates to inject content.

This loads modules/products/views/listing.php and passes $products to it.

Auto-Detection

If you don't specify view_module, it uses the first URL segment. If you don't specify view_file, it defaults to index.

If the view file doesn't exist, shows a red error message with the expected path.


Extract File Info

The function splits a file path into name and extension.


Sort Arrays

The function sorts associative arrays by a specific key.

Sort Objects

The function does the same thing but for arrays of objects.


Detect Trongate MX Requests

The function checks if the current request came from Trongate MX (Trongate's JavaScript library for dynamic page updates).

Use to handle AJAX requests differently from normal page loads - no extra routing required.

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