MV object
All templates use the $mv object to access models and other functions.
Own public properties
- $root_path - path (URL) to the site root (usually '/' on the production domain), APP_FOLDER parameter in the .env file
- $media_path - path (URL) from the site root to the media folder
- $views_path - absolute path from the root of the file system to the folder with views templates
- $include_path - absolute path from the root of the file system to the site, used for the include and require functions
- $domain - domain name from the APP_DOMIAN parameter of the .env file
These properties are closely related to section System settings.
Own methods of the $mv object
- redirect(), reload(), display404() - redirect to other pages within the site, more details in the section Redirects
- checkUrlPart($index) - check the URL for the required part, more details in the section Router object
Objects inside the $mv object
- registry - access to settings from configuration files, more details in the section System settings
- router - router, Router object
- db - database manager that performs Direct queries to the database
- cache - caching in templates
All active models and plugins are available in the $mv object by their names.
Accessing models and plugins through the $mv object allows you to create the necessary objects only when needed and improves performance.
//Including part of the template
include $mv -> views_path.'main-header.php';
include $mv -> views_path.'parts/left-column.php';
//Using built-in objects
$mv -> db -> getCell("SELECT `email` FROM `users` WHERE `id`='236'");
//Accessing models
echo $mv -> pages -> displayMenu(74);
$user = $mv -> users -> find(['email' => 'aaa@bbb.cc', 'active' => 1]);
//Accessing plugins
$mv -> shopping_cart -> addProduct(34, 1) -> recountCart();
//Access to simple model data
echo $mv -> options -> phone;
//Redirect
$mv -> redirect('/home/page');
//Reload page with additional GET parameters
$mv -> reload('?success')
//Transition to 404 error
$mv -> display404();
Previous section
Router object