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 baseController class.
Creating controllers
Controllers should be placed in theapp/Controllers directory and extend Aeros\Src\Classes\Controller:
app/Controllers/UserController.php
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
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. TheView class handles template resolution and variable extraction.
Rendering views
Use theview() helper function to render views:
View resolution
Views use dot notation for nested directories. TheView class automatically resolves the path (View.php:52-57):
View variables
Variables passed to views are automatically extracted and made available as PHP variables:Flash variables
Aeros supports flash variables for one-time data (typically used after redirects):Models
Models represent your application’s data layer and business logic. Aeros provides a baseModel 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:- Request - HTTP request arrives at the application
- Router - Matches the request to a registered route
- Middleware - Executes any route middleware
- Controller - Handles the request logic
- Model - Performs data operations (if needed)
- View - Renders the response template
- 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.
Related resources
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