1001Ferramentas
๐Ÿ˜Generators

PHP MVC Skeleton Generator

Generate minimal PHP MVC skeleton (Controller, Model, View) from a resource name.


  

MVC in PHP: a 45-year-old idea that still ships web apps

The Model-View-Controller pattern was formalised in 1979 by Norwegian computer scientist Trygve Reenskaug while working on Smalltalk-76 at Xerox PARC. Forty-five years later it remains the dominant architectural pattern for server-rendered web frameworks because the separation it enforces is genuinely useful: Model encapsulates data and business rules, View renders user-facing output, Controller orchestrates input and chooses which view to display. In a PHP request lifecycle the front controller (typically public/index.php) bootstraps the framework, the router maps the URL to a controller method, the controller asks the model for data and returns a view; the framework converts the view to an HTTP response.

PHP MVC frameworks arrived in waves. CakePHP (2005) and CodeIgniter (2006) translated Rails ergonomics to PHP 5. Symfony (2005) pushed enterprise patterns (dependency injection, event dispatcher) and remains the kernel beneath Drupal and Laravel. Laravel, created by Taylor Otwell in 2011, became dominant by combining Symfony components with developer-friendly conventions and is the de-facto choice for new PHP projects in 2026.

Anatomy of a Laravel skeleton

app/
  Http/Controllers/UserController.php
  Models/User.php
  Services/UserService.php
resources/views/users/index.blade.php
routes/web.php
database/migrations/2026_01_01_create_users_table.php
config/database.php
public/index.php   # front controller
  • Routing in routes/web.php: Route::get('/users', [UserController::class, 'index']);
  • Eloquent ORM uses the Active Record pattern: User::where('active', 1)->orderBy('name')->paginate(20);
  • Blade templating with double-brace escaping: @foreach($users as $u) {{ $u->name }} @endforeach
  • Migrations as schema-as-code: php artisan make:migration create_users_table
  • Composer + PSR-4 autoloading maps App\Models\User to app/Models/User.php automatically.

Common pitfalls and the Service Layer

The two recurring sins in PHP MVC are fat controllers โ€” methods of 200 lines mixing validation, persistence, e-mail and billing โ€” and N+1 query bugs in Eloquent. Mitigate the first by extracting business logic to dedicated Service classes (app/Services/) and injecting them into the controller; the controller's job becomes parse input โ†’ call service โ†’ render view. Mitigate the second with eager loading: User::with('posts.comments')->get(); issues two extra queries instead of N. Tools like Laravel Telescope and Clockwork surface the offending traces during development.

Modern PHP: Octane, Livewire, Inertia

Recent additions push PHP into territory once reserved for Node and Go. Laravel Octane runs the framework as a persistent worker on Swoole or RoadRunner, eliminating per-request bootstrap and routinely delivering 5โ€“10ร— more requests per second. Livewire (Caleb Porzio) and Inertia.js (Jonathan Reinink) provide alternatives to building a separate SPA: Livewire keeps state on the server and ships HTML diffs over WebSockets; Inertia ships a Vue/React app whose props come straight from Laravel controllers. Both let an MVC team build SPA-like UX without an additional API layer.

FAQ

Do I really need a framework? No โ€” pure PHP with a router (Slim, FastRoute) and a templating engine (Twig, Plates) can implement MVC perfectly. A framework saves you weeks of writing routing, ORM, validation, mailer, cache, queues and migrations from scratch. For a project larger than a single CRUD form, the savings dwarf the learning curve.

Is Laravel overkill for a small site? If you really only need three pages, Slim or Lumen (Laravel's micro-framework cousin, archived in 2022 but still widely used) are lighter. Laravel itself is fine on modest hardware โ€” its base footprint is ~25 MB RAM per request.

Is PHP fast enough for production? Yes. PHP 8.3 with OPcache and JIT serves the majority of the web (Wikipedia, Slack landing, Etsy, much of WordPress). For latency-sensitive workloads, Octane closes the gap with Node/Go.

How does MVC compare with HMVC, MVVM and Clean Architecture? HMVC nests MVC triads as widgets (CodeIgniter HMVC, Kohana); MVVM (popular in WPF/Vue) replaces the controller with a data-binding ViewModel; Clean / Hexagonal Architecture pushes the model into pure-PHP "domain" classes with framework concerns isolated at the boundary. All three keep the same separation goal โ€” they just slice it differently.

Related Tools