MVC App
Controller, view, and route — classic MVC pattern with Nexphant.
Setup
bash
composer create-project nexphant/nexphant my-app --template mvc
cd my-appController
php
<?php
namespace App\Controllers;
use Nexphant\Get;
use Nexphant\Route;
use Nexphant\Request;
use Nexphant\View\ViewResponse;
#[Route('/')]
class HomeController
{
#[Get('/')]
public function index(Request $request): ViewResponse
{
return view('home', ['title' => 'Nexphant']);
}
#[Get('/about')]
public function about(): ViewResponse
{
return view('about', ['title' => 'About']);
}
}View
resources/views/home.php:
php
<!doctype html>
<html>
<head><title><?= $title ?></title></head>
<body>
<h1>Welcome to <?= $title ?></h1>
</body>
</html>view() Helper
php
view('home', $data); // resources/views/home.php
view('admin.dashboard', $data); // resources/views/admin/dashboard.phpRun
bash
php app.php
# open http://localhost:8080