1. Generate the controller
aml make:controller AboutAML creates src/controllers/AboutController.php. A controller is an ordinary PHP class extending Controller so it can use framework tools, including view().
2. Fill this exact file
src/controllers/AboutController.php
<?php
declare(strict_types=1);
namespace App\Controllers;
use PHPAML\Http\Request;
use PHPAML\Http\Response;
use PHPAML\Mvc\Controller;
final class AboutController extends Controller
{
public function index(Request $request): Response
{
return $this->view('about.php');
}
}index() is the action called by the route. Request represents the received request. Response ensures the action returns an answer PHPAML understands. view('about.php') finally requests src/views/about.php.
3. Create the view
src/views/about.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About</title>
</head>
<body>
<main>
<h1>About Reading List</h1>
<p>My first PHPAML page.</p>
</main>
</body>
</html>This view contains HTML because its job is presentation. It remains a PHP file: soon we will display dynamic values in it.
4. Connect the address to the controller
src/routes/WebApp.php
<?php
declare(strict_types=1);
namespace App\Routes;
use App\Controllers\AboutController;
use App\Controllers\HomeController;
use PHPAML\Routing\Route;
final class WebApp extends Route
{
protected function routes(): void
{
$this->get('/', [HomeController::class, 'index']);
$this->get('/about', [AboutController::class, 'index']);
}
}get means the page answers a normal browser visit. The array names the class, then the method to call. The use line makes AboutController available in this file.
5. Check immediately
aml routes
# GET /about AboutController::indexThen open http://127.0.0.1:8910/about. If the page appears, the route, controller, and view are correctly connected.