Table of Contents
21. A Simple View — When Presentation Deserves a Home
— giving output a place to breathe
Once our controller returns meaning
— an array, a message, a status
— we eventually need to show something to a human.
That’s where a view comes in.
This completes the “outer layer” of the request cycle:
Router → Controller → Domain* → Response → View
A view is simply where meaning becomes presentation.
Just a small, intentional home for presentation.
* Aside:
Domain — the ideas our application cares about
(users, posts, orders)
1. What a View Really Is
A view is simply:
- A file that knows how to turn data into something a human can see.
That’s it. A view does not
make decisions.
perform actions.
coordinate behavior.
It presents.
2. The Smallest View We Can Write
Here is the simplest possible view:
<!-- about.php --> <h1>About</h1> <p>This is the about page.</p>
Our controller:
function about(): string { return render('about.php'); }
Our render helper:
function render(string $file, array $data = []): string { extract($data); ob_start(); include $file; return ob_get_clean(); }
This is the shape:
- a file
- some data
- a rendered result
Everything else is refinement.
3. Passing Data to a View
Let’s say we want to show a user:
// user.php <h1><?= htmlspecialchars($name) ?></h1> <p>Email: <?= htmlspecialchars($email) ?></p>
Our controller:
public function show(string $id): string { $user = $this->users->find($id); return render('user.php', [ 'name' => $user->name, 'email' => $user->email, ]); }
The controller returns meaning.
The view turns it into presentation.
This separation keeps our application simple.
4. Views Should Stay Thin
A view should not:
- query the database
- call services
- create entities
- perform business logic
- validate data
- make decisions
A view’s job is simply:
Receive data.
Present it.
Nothing more.
5. When Presentation Becomes a Concept
As soon as we have:
- repeated headers
- repeated footers
- repeated layouts
- repeated HTML patterns
…we feel the friction.
This is the moment when presentation becomes a concept, and we give it a home:
function layout(string $content): string { return render('layout.php', ['content' => $content]); }
Our controller:
return layout(render('user.php', $data));
Our layout:
<!-- layout.php -->
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
<?= $content ?>
</body>
</html>
This is the entire mental model of templating — simply expressed.
6. Why This Matters in the AI Era
When we ask AI for a view, it may:
- generate a full templating engine
- mix logic and presentation
- embed SQL in HTML
- create a framework
- over‑engineer the render function
- produce unsafe output
Our literacy lets us steer the conversation:
“Keep the view simple.”
“No logic in the view.”
“Escape output.”
“Use a small render helper.”
“Keep the controller thin.”
We’re not memorizing templating systems
— we’re shaping intention.
7. When to Ask AI for a View
The moment when presentation starts repeating
Here’s what that moment looks like.
We start with:
“Return HTML for the user.”
AI gives us:
return "<h1>$name</h1><p>Email: $email</p>";
Then we ask:
“Also add a header.”
AI concatenates more strings.
Then we ask:
“Also add a footer.”
More concatenation.
Then we ask:
“Also escape the output.”
Even more logic.
We feel the friction.
We feel the repetition.
We feel the concept.
This is the moment to say:
“Give me a simple view file and a render helper. Move all presentation into the view.”
AI will produce a clean view.
This is the literacy we’re learning:
When presentation repeats, we ask for a view.
When presentation grows, we give it a home.
8. The Mental Model in One Sentence
A view is where meaning becomes presentation
— simple, intentional, and calm.
Once we see this shape, we can collaborate with AI on any presentation layer
— from a tiny script to a full application —
without losing clarity.
Tony de Araujo —New York
