Router object

This object is located inside the main "$mv" object and responsible for processing the passed URL.

  • getUrl() - returns cleared requested URL, if index page was requested, returns "/"
  • getUrlParts() - returns an array of URL parts
  • getUrlPart($index) - returns part of URL by given index (starts from 0)
  • getRoute() - returns the name of the file of included template
  • isIndex() - validates if the current page is the main page (index page)
  • isLocalHost() - check if the project located in local sever
  • defineCurrentPage($start_key) - described in Pagination section

There is "checkUrlPart($index [, $extra_check])" method in "$mv" object that contains Router object, as described in MV object section. This method checks if there is a part of URL under given index and returns it if so, otherwise shows 404 error. As an optional parameter "$extra_check" will be passed, if its value is "numeric", then this searched part of URL should be an integer.

Samples

///Trying to get 3rd part from URL like "/articles/32/83/"
$article_id = intval($mv -> router -> getUrlPart(2));
$mv -> display404($article_id); //If no such an element, then page is not found

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

//Redirect with a parameter, that contains the back path
$mv -> redirect("create-order/?from=".$mv -> router -> getUrl());

//Checks if there is a numeric 2nd part in URL of "/user/652/"
//If not, show 404 error
$user_id = $mv -> checkUrlPart(1, "numeric");