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
View Files
With Trongate, views are just PHP files. That’s it.
HTML + <?= $var ?> = dynamic page.
No template engine. No learning curve. Just PHP.
Where They Live
Each module can have one views directory. Put your view files in it. Done.
modules/
users/
Users.php
Users_model.php ← optional
views/
users_list.php
user_profile.phpThe text above demonstrates some file and directory locations for a hypothetical 'users' module.
How to Load One
View files can be loaded from any controller by using Trongate's view() method:
$this->view('users_list', $data);Trongate renders views/users_list.php. That’s it.
Passing Data
$data['users'] = $this->model->get();
$this->view('users_list', $data);In the view:
<?php foreach ($users as $user): ?>
<p><?= $user->name ?></p>
<?php endforeach; ?>Return as String (Pro Move)
Need HTML as a variable?
$html = $this->view('email_template', $data, true);Third arg = true → returns a string. No output. You control it.
Never put logic in views.
if, foreach = OK.
Queries, auth, redirects = NO. That’s controller/model territory.
Use Trongate’s out() string helper to automatically escape user-generated content, protect your site from XSS and ensure proper encoding.
<?= out($name) ?> <!-- HTML (default format) -->
<?= out($xml, 'xml') ?> <!-- XML -->
<?= out($json, 'json') ?> <!-- JSON -->
<?= out($js, 'javascript') ?> <!-- JS -->Remember, when you're dealing with Trongate, PHP is the template engine.
100% Native PHP. 100% nailed.
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.