Skip to main content
Aeros follows the Model-View-Controller (MVC) architectural pattern, providing a clean separation of concerns between your application’s data, presentation, and business logic.

Overview

The MVC architecture in Aeros separates your application into three main components:
  • Models - Handle data and business logic
  • Views - Manage presentation and user interface
  • Controllers - Coordinate between models and views

Controllers

Controllers are the entry point for handling HTTP requests and coordinating application logic. All controllers in Aeros extend the base Controller class.

Creating controllers

Controllers should be placed in the app/Controllers directory and extend Aeros\Src\Classes\Controller:
app/Controllers/UserController.php
<?php

namespace App\Controllers;

use Aeros\Src\Classes\Controller;

class UserController extends Controller
{
    public function index()
    {
        return view('users.index');
    }
    
    public function show($id)
    {
        // Handle user display logic
        return view('users.show', ['id' => $id]);
    }
}

Controller methods

Controller methods are automatically invoked by the router when a matching route is found. Parameters from the route are automatically injected into the method:
routes/web.php
<?php

use Aeros\Src\Classes\Router;

// Maps to UserController::show($id)
Router::get('/user/:id', 'UserController@show');
The router uses reflection to dynamically assign route parameters to controller method arguments (Route.php:188-201).
If a route parameter doesn’t match a method parameter name, Aeros will throw an exception.

Views

Views are responsible for rendering the presentation layer of your application. The View class handles template resolution and variable extraction.

Rendering views

Use the view() helper function to render views:
// Render a simple view
return view('welcome');

// Pass variables to the view
return view('users.profile', [
    'name' => 'John Doe',
    'email' => '[email protected]'
]);

View resolution

Views use dot notation for nested directories. The View class automatically resolves the path (View.php:52-57):
// Resolves to: /views/users/profile.php
view('users.profile');

// Resolves to: /views/admin/dashboard.php
view('admin.dashboard');

View variables

Variables passed to views are automatically extracted and made available as PHP variables:
// In your controller
return view('user.profile', ['username' => 'john_doe']);
<!-- In your view: views/user/profile.php -->
<h1>Welcome, <?= $username ?></h1>

Flash variables

Aeros supports flash variables for one-time data (typically used after redirects):
// Flash variables are automatically extracted in views
if (!empty($_SESSION['flash_vars'])) {
    extract($_SESSION['flash_vars']);
    $_SESSION['flash_vars'] = [];
}

Models

Models represent your application’s data layer and business logic. Aeros provides a base Model class for database interactions.
For detailed information about working with models and database operations, see the Models documentation.

Request flow

Here’s how a typical request flows through the MVC architecture:
  1. Request - HTTP request arrives at the application
  2. Router - Matches the request to a registered route
  3. Middleware - Executes any route middleware
  4. Controller - Handles the request logic
  5. Model - Performs data operations (if needed)
  6. View - Renders the response template
  7. Response - Sends the output back to the client

Best practices

Keep controllers thin

Controllers should coordinate logic, not contain it. Move complex business logic to models or service classes.

Use type hints

Leverage PHP type hints in controller methods for better code clarity and error prevention.

Organize views logically

Use subdirectories to group related views (e.g., users/, admin/).

Validate input

Always validate and sanitize user input in your controllers before processing.

Routing

Learn how to define and manage routes

Request lifecycle

Understand how requests flow through Aeros

Middleware

Add layers to your request processing

Request lifecycle

Understand how requests are processed from start to finish

Middleware

Add middleware to filter and process requests

Service container

Manage dependencies with the service container

Build docs developers (and LLMs) love