The controller prepares
Replace only the index() method of AboutController. The second view() argument is an associative array: every key becomes a name available in the view.
public function index(Request $request): Response
{
return $this->view('about.php', [
'projectName' => 'Reading List',
'bookCount' => 3,
]);
}projectNamename used by the view
Reading Listvalue prepared by the controller
The view displays without blindly trusting
src/views/about.php
<main>
<h1><?= htmlspecialchars($projectName, ENT_QUOTES, 'UTF-8') ?></h1>
<p>You track <?= (int) $bookCount ?> books.</p>
</main><?= ... ?> is a short form of echo. htmlspecialchars converts characters that could be interpreted as HTML. This protection matters whenever a value may come from a form, URL, or database. The (int) cast guarantees a number here.
Follow the value
'bookCount' => 3about.php$bookCount3 booksThe view does not fetch data itself. The controller gives it data explicitly, making the flow readable and testable.
BEGINNER QUESTIONS
Normal questions at this stage.
Why not write the number directly in the view?
Because a real value will change. Passing it prepares the code for service or database data.
Can I pass an object?
Yes. The initial project already passes a HomeModel to home.php.
Must every text be escaped?
Escape dynamic values displayed in HTML, especially those coming from users or external sources.