Welcome to FrostSW!

FrostMVC PHP Framework

Documentation   |   Version
FrostMVC is a PHP framework for beginners. A perfect framework to introduce MVC architecture.

FrostMVC provides a simple and easy-to-use structure for building web applications, with beginners in mind. It is designed to be simple to understand, yet flexible and modular. It comes with MySQL database access through the Model class and uses Twig for Views. FrostMVC is not open-source, but it is free to use for personal and commercial web applications.

New to FrostMVC? Start with Getting Started to install and configure it, then follow the guides: Routing, Controllers, Models & Database and Views & Twig. Every class and method is listed in the API Reference.

How a request works

  1. index.php starts the framework in core/, which reads app/settings.php and app/routes.php.
  2. POST requests are checked for a valid CSRF token.
  3. The first part of the URL selects a function in routes.php, which hands the request to a controller with View::route().
  4. The next part of the URL selects the controller method; the rest become its arguments.
  5. The controller reads input, uses models to query the database, and renders a Twig view with View::get().

File structure

FrostMVC keeps a small, flat file structure that is easy to navigate and customise:

app/

The user space of the framework, where your models, views and controllers go, together with routing and configuration. All PHP classes in app/ use your app namespace ($config['namespace']), e.g. MyApp\controllers and MyApp\models.

  • controllers/ — classes that handle requests: read input, call models, render views.
  • models/ — one class per database table, with a built-in query builder.
  • views/ — Twig templates (.php.twig).
  • routes.php — maps each URL path to a controller.
  • settings.php — site details, environment, database, sessions and CSRF protection.

assets/

Public files served directly to the browser: stylesheets, images and scripts. Link to them with {{ RESOURCEPATH }} in views. assets/tmp holds runtime files such as logs (Logs::setDirectory('assets/tmp/logs') in the starter settings).

core/

The framework itself. frostfw.php starts the app and routes the request, loader.php autoloads classes by namespace, and classes/ contains the FrostMVC classes you import in your code, such as use FrostMVC\Model;. Do not edit these files: replace the whole folder when you upgrade FrostMVC. Their methods are documented in the API Reference.

libraries/

Your own reusable code and third-party packages. Classes go in libraries/ (namespace MyApp\libraries) and helper functions in libraries/helpers/ (namespace MyApp\libraries\helpers\general in the starter). Load them at startup with $config['libraries'] in settings.php, or on demand with $this->require->library() and ->helper() in a controller. Composer packages are installed in libraries/vendor: run composer install in libraries/. The starter uses Twig and PHPMailer.

What's new in FrostMVC 1.3

  • Namespaces. Framework classes are in the FrostMVC namespace and your app classes in your own namespace, loaded automatically.
  • Configuration array. settings.php builds a $config array and calls Site::addInstance($config), replacing the $instance->setURL()-style setters.
  • Class-based routing. View::route(BlogController::class, $pages) instead of a controller name string.
  • Sessions. Encrypted session values, optional Memcached storage, and Session::flash() / session.flash() for read-once messages.
  • Query builder. Result caching with cache(), alias(), cast(), from() subqueries and forUpdate() row locking.
  • Database connection. DB options for SSL, sockets, ports, charset, connect timeout and automatic retries.
  • Smaller additions. Form::val(), Functions::default(), Date_Time::ConvertToTimeZone(), and the FlashLog key-value store.

Upgrading from 1.0

  1. Replace the core/ folder and update the version in index.php.
  2. Rewrite app/settings.php in the $config format (see Configuration) and choose a namespace.
  3. Add namespace MyApp\controllers;, MyApp\models, MyApp\libraries and MyApp\routes to your files, and import the framework classes you use (use FrostMVC\View;…).
  4. Change View::route('BlogController', $pages) to View::route(BlogController::class, $pages).
  5. In views, replace session.get(...) + session.remove(...) pairs with session.flash(...).