Object of Router Class

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

  • getUrl() - returns requsted URL, if index page was requested, returns "/"
  • getUrlParts() - returns an arrays of URL parts
  • getUrlPart($index) - returns part of URL under under given order number (starting from 0)
  • getRoute() - returns the name of the file of included template
  • isIndex() - validates if the current page is the main page (index)
  • isLocalHost() - check if the project located in local host
  • defineCurrentPage($start_key) - described in Pagination section Pagination

There is "checkUrlPart($index [, $extra_check])" method in "$mv" that is in closely bind with 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 it’s value is "numeric", then this part of URL should be an integer.

Samples

///Trying to get 3rd part from URL as "/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 - 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());

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