MV framework logo
  • Architecture
  • Philosophy
  • Admin panel
  • Support
  • Feedback
Documentation
Download .zip version 3.2.0 from 25.12.2024
  • Architecture
  • Philosophy
  • Admin panel
  • Support
  • Feedback
Getting started
  • Installation and launch
  • Folder structure
  • Launching a simple website
  • Pre-installed models
  • SQLite getting started
  • System settings
  • Migrations
  • Debugging
Models
  • General principles of models
  • Data types
  • Model setup
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Managing simple models
  • Additional features
Templates and routing
  • General principles of templates
  • Router object
  • MV object
  • Create a new template
  • Output of data in template
  • Record object
  • Files and images
  • Date and time
  • Redirects and http
  • Sending email
  • Special methods
Forms
  • Creating forms
  • Setting up form fields
  • Validating form fields
  • Form security
  • Working with form data
  • Using data from models
  • Form methods
SQL queries
  • Query builder
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
Additional
  • AJAX
  • Plugins
  • Caching
  • Security
  • Admin panel add-ons
Documentation
Getting started
  • Installation and launch
  • Folder structure
  • Launching a simple website
  • Pre-installed models
  • SQLite getting started
  • System settings
  • Migrations
  • Debugging
Models
  • General principles of models
  • Data types
  • Model setup
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Managing simple models
  • Additional features
Templates and routing
  • General principles of templates
  • Router object
  • MV object
  • Create a new template
  • Output of data in template
  • Record object
  • Files and images
  • Date and time
  • Redirects and http
  • Sending email
  • Special methods
Forms
  • Creating forms
  • Setting up form fields
  • Validating form fields
  • Form security
  • Working with form data
  • Using data from models
  • Form methods
SQL queries
  • Query builder
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
Additional
  • AJAX
  • Plugins
  • Caching
  • Security
  • Admin panel add-ons
MV tracker

Router object

This object is located inside the main $mv object and is responsible for working with the passed URL and determining the route.

  • getUrl() - returns the requested URL, if the index page is requested, it will return '/'
  • getUrlParts() - returns an array of URL parts
  • getUrlPart($index) - returns the part of the URL under the desired ordinal number, starting with 0
  • getRoute() - returns the file name of the included template
  • isIndex() - checks whether the current page is the main page

Closely related to the Router object is the checkUrlPart($index [,$extra_check]) method in the $mv object, which is described in the section MV object. This method checks if there is a part of the URL under the specified index and if there is, it returns it, and if not, it shows a 404 error. $extra_check is passed as an additional parameter, if its value is 'numeric', then this part of the URL must be numeric.

//We try to extract the third part from the URL, a request like '/articles/32/83'
$article_id = intval($mv -> router -> getUrlPart(2));

//If there is no such element, then the page was not found
$mv -> display404($article_id);

//If the main page is requested, we include the left column
if($mv -> router -> isIndex())
    include $mv -> views_path.'parts/left-column.php';

//Redirect with a parameter containing the return path
$mv -> redirect('order/create?from='.$mv -> router -> getUrl());

//Check if the URL like '/user/652' has a numeric second part,
//if not, show a 404 error
$user_id = $mv -> checkUrlPart(1, 'numeric');

Previous section

General principles of templates

Next section

MV object
MV workshop banner
MV tracker

© 2014-2025, MV framework team

MV tracker project Github