Welcome to FrostSW!

FrostMVC PHP Framework

Getting Started   |   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, targeting developers new to the MVC structure. 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.

Prerequisites

FrostMVC needs the following to be installed before you run it:

  • PHP 8.1 or later
  • Apache 2.4 or later, with mod_rewrite enabled (FrostMVC's .htaccess sends every URL to index.php)
  • MySQL 5.7 or later, or MariaDB 10.3 or later
  • Composer 2 (optional — to add third-party packages)
  • Memcached (optional — to store sessions in memory; FrostMVC uses regular PHP sessions without it)

You can install PHP, Apache and MySQL at once with one of these packages:

To add third-party PHP libraries, install Composer.

Download

Download FrostMVC to get the starter project files and begin right away.

Download FrostMVC

Installation

  1. Extract the downloaded zip file.
  2. Copy the extracted FrostMVC folder to your web server's document root:
    • WAMPServer: C:/wamp64/www (or C:/wamp/www)
    • XAMPP: C:/xampp/htdocs
    • MAMP: /Applications/MAMP/htdocs, or the document root set in MAMP's preferences
  3. Install the Composer packages (Twig and PHPMailer): open a terminal in the libraries folder and run composer install. Skip this if the download already includes libraries/vendor.
  4. Start Apache and MySQL.
  5. Open http://localhost/FrostMVC in your browser. You should see the Welcome page.
    You can rename the folder; update $config['url'] in app/settings.php to match. A virtual host (e.g. http://myproject.test) is recommended.

Configuration

All settings are in app/settings.php. It fills a $config array, creates the site from it, and then sets up sessions, CSRF protection and the database.

Site details

$config['url'] = Site::getProtocol() . '://' . Form::fis('HTTP_HOST') . (strpos(Form::fis('HTTP_HOST'), 'localhost') !== false ? '/FrostMVC' : '');
$config['name'] = "My Website";
$config['email'] = "hello@mywebsite.com";
$config['namespace'] = 'MyApp';
$config['environment'] = "Development";
$config['timezone'] = "Asia/Manila";
urlYour site's address, without a trailing slash. It becomes BASEPATH (and RESOURCEPATH for assets/). A wrong value gives 404 errors. The starter detects the host, adding the folder name on localhost.
name, email, contact, mobile, address, facebook, FBID, twitterSite details, read back with getName(), getEmail()… in PHP, or {{ site.getName() }} in Twig.
namespaceThe PHP namespace of your app. Controllers use MyApp\controllers, models MyApp\models, libraries MyApp\libraries and routes MyApp\routes; FrostMVC autoloads them.
environment'Development' shows detailed errors, enables /phpinfo and Twig's dump(). 'Production' hides them. Always use 'Production' on a live site.
timezoneA PHP timezone name, e.g. 'Asia/Manila' or 'UTC'.

Libraries and helpers

List the helpers (libraries/helpers/*.php) and library classes (libraries/*.php) to load on every request:

$config['libraries'] = [
    ['helper', 'generalHelper'],
    ['library', 'TwigExtensions'],
];

Load others only where you need them, from a controller: $this->require->helper('myhelpers') or $this->require->library('Mailer', $this).

Creating the site

$instance = Site::addInstance($config);

This applies the configuration. Afterwards the site is available as $instance in settings.php, as getInstance() or Site::$instance anywhere else, and as site in Twig. See the Site reference.

Twig global variables

Add variables that every view can use:

$instance->twig->addGlobal('version', '1.0.0');
$instance->twig->addGlobal('nonce', sha1(Date_Time::Now() . rand()));

In a view, {{ version }} prints 1.0.0. See Views & Twig for the variables FrostMVC provides.

Logs and sessions

Logs::setDirectory('assets/tmp/logs');
Session::setOption('cookie_secure', $config['environment'] === 'Production' ? 1 : 0);
Session::setOption('cookie_samesite', '');
Session::memcached('127.0.0.1');
  • Logs::setDirectory() — where Logs::write() and query errors are logged.
  • Session::setOption() — PHP session cookie options. Keep cookie_secure on in Production (HTTPS only).
  • Session::memcached() — stores sessions in Memcached at that address. Without the Memcached extension or server, FrostMVC falls back to regular PHP sessions.

CSRF protection

Every POST request must carry a valid CSRF token; forms opened with Form::start() include it automatically.

Security::$CSRFTokenConfig = [
    "regenerate" => false,
    "token-name" => "x-csrf-token",
    "exclude" => []
];
  • regenerate — issue a new token after each check. Turn it on for sensitive forms such as login and registration, so a token cannot be reused.
  • token-name — the name of the token field and cookie.
  • exclude — URL paths (full or partial) that skip the check, e.g. webhooks that are called by other servers.

Database

FrostMVC supports MySQL and MariaDB.

$dbname = "mydatabase";
$servername = "localhost";
$username = "root";
$password = "mypassword";

define("TABLE_PREFIX", "");
define("TABLE_SUFFIX", "_tbl");

DB::$db = new DB($servername, $username, $password, "$dbname");

TABLE_PREFIX and TABLE_SUFFIX are added to model names to find their tables: with the settings above, the Accounts model uses accounts_tbl. Set both to '' if your tables have no prefix or suffix. See Models & Database.

Loading your extensions

Call your libraries' setup methods at the end of settings.php, after everything else is configured. The starter registers its Twig functions and filters this way:

(new TwigExtensions)->load();

Next steps

Learn how the pieces fit together, then look up any class or method in the API reference.

Read the Documentation API Reference