FrostMVC provides a simple and easy-to-use structure for building web applications, with the beginners in mind. It is designed to be extremely simple, easy to understand, and yet flexible and modular, targeting developers new to MVC structure. It comes with built-in support for MySQL database access through the Model class and uses Twig for Views templating. Currently, FrostMVC is not under open-source, however it is free to use for personal and commercial web applications.
FrostMVC is a PHP Framework. It would require the following software or applications to be installed first before running the framework.
You can install the above applications at once by installing WAMPServer or XAMPP
If you are using macOS, you can install MAMP from here https://www.mamp.info/en/downloads/
You can add third-party PHP libraries to FrostMVC using Composer. Simply the following to install Composer here https://getcomposer.org/download/
Download FrostMVC to get the basic templated project files that you can use to start right away!
Once you downloaded the zip file of FrostMVC, you can simply follow these steps:
FrostMVC-master you extracted from Step 1 to the following folder:
FrostMVC-master folder and paste it to C:/wamp/www or C:/wamp64/wwwC:/xampp/htdocsFrostMVC-master to any folder name you prefer. It is also advisable to use a Virtual Host instead.There are certain values that FrostMVC would require to be configured first before it can fully run. These configurations can be found in settings.php file located under app directory
You can change the properties of your website using the $instance global variable, which is an instance of Site class.
The following serves as your guide to edit the app/settings.php file:
setURL(string url) - change the configured website URL.
Example: $instance->setURL('https://www.mywebsite.com')
You can get this value using the following:
$instance->getURL() method or BASEPATH constant.twig files, you can use {{ site.getURL() }} or {{ BASEPATH }}BASEPATH and RESOURCEPATH relies to the value configured in setURL() method.setURL() is not correctly configured.setName(string name) - You can set the name of your website using this method.
Example: $instance->setName('My Website')
You can get this value using the following:
$instance->getName() method.twig files, you can use {{ site.getName() }}setEnvironment(enum Development|Production) - Set the value to 'Development' if you want the error messages to be displayed, otherwise set the value to 'Production' to hide these messages.
Example: $instance->setEnvironment('Production')
You can get this value using the following:
$instance->getEnvironment() method.twig files, you can use {{ site.getEnvironment() }}'Development' environment,
/phpinfo in your website's URL to display the current information of PHP.dump() method in twig files to display the values of a variable.These features will be disabled when the website is configured to 'Production' environment.
Always set environment to 'Production' before you deploy your website.
$instance global variable can also be accessed through the following:
Site::$instance — a static variable from Site class that references $instance global variable.Site::$instance->getName()
getInstance() — a helper function that returns $instance global variable.getInstance()->getName()
Site class, you can check the following documentation: Site class
FrostMVC uses Symfony's Twig as template engine for Views.
You can use the $instance->twig variable to set Twig configuration
In FrostMVC, you can add variables that can be accessed throughout your .twig files using the addGlobal(string variableName, any value) method.
Example: $instance->twig->addGlobal('myVariable', 'Hello World!')
In .twig files, you can access them as {{ myVariable }} to display its value Hello World!
You can add your own helper files and custom classes to extend the functionality of FrostMVC. Helpers and custom classes must be saved to the following directories:
libraries/helpers folder.libraries folder.To make these helper files and custom classes be recognisable to FrostMVC, you have to load them using $instance->require object, which is an instance of Loader class.
helper() method.$instance->require->helper('myhelpers')libraries/helpers/myhelpers.php
library() method$instance->require->library('MyCustomClass')libraries/MyCustomClass.php
You can implement a CSRF (Cross-site Request Forgery) token as additional security to your forms.
Security::$CSRFTokenConfig = [
'regenerate' => true,
'token-name' => 'x-csrf-token',
'exclude' => []
];
regenerate (boolean) - indicates whether FrostMVC will generate a new token for each request. It is recommended to turn this to true only at registration and login forms to prevent used tokens to be submitted more than twice.token-name (string) - used to assign a name to the token that FrostMVC will generate.exclude (string array) - the list of URL paths that will be excluded from CSRF token validity checking. This can be a full URL or a partial value.Please note that currently, FrostMVC only supports MySQL or MariaDB databases as of the moment.
$dbname = 'testdb';
$servername = 'localhost';
$username = 'root';
$password = 'mypassword';
define('TABLE_PREFIX', '');
define('TABLE_SUFFIX', '_tbl');
DB::$db = new DB($servername, $username, $password, $dbname);
$dbname - this refers to the database name$servername - this refers to the host of where the database is connected. The default value is 'localhost'.$username - the user that PHP will use to connect to the MySQL or MariaDB instance. To learn more about how to manage users in MySQL, please read this article here.$password - The password that your database user account is associated to.
For MySQL table names, developers might be using prefixes, for example tbl_profiles and/or suffixes, for example profiles_tbl, where tbl_ or _tbl is the prefix or suffix.
You can specify these by using the constants TABLE_PREFIX and TABLE_SUFFIX.
The Model class will append the values of these constants to the class names behind the scenes during the transaction.
define('TABLE_PREFIX', 'tbl_');
define('TABLE_SUFFIX', '');
define('TABLE_PREFIX', '');
define('TABLE_SUFFIX', '_tbl');
define('TABLE_PREFIX', '');
define('TABLE_SUFFIX', '');
Model class, read the following article hereInitiator methods are methods that is being called to initialise custom classes and libraries. It is recommended to call the initiator methods at the last part of the settings.php file.
If we want to load the twig extension methods from TwigExtension library class, we can load them first using the load() method.
(new TwigExtension)->load();
TwigExtension library class, read the following article here
You can learn more about the classes and helpful examples of FrostMVC.