UrlMapper

The Urlmapper class is a simple navigation tool that makes it easier to map url links. It separates each section of a link to a clickable link. The following methods are used to map urls.

  1. setbase
  2. map
The following keywords should be noted:

keywords
    
    url  : supplied url to be processed

    path : supplied url to be compared

    pointer : navigation pointer or icon (accepts html tags)
    
                                    

Initializing Urlmapper class
The UrlMapper tool can be easily initialized as shown below.

Sample: Initializing Input
  $url  = new UrlMapper;
                                            
This class has only two methods which are setbase() and map(). These are explained below:
map
The map() method is used to map urls. It divides each section of a url link to a clickable link.

Syntax
  $url->map($url, $pointer); 

  
    where: 

    $url: url to be sectionalized 

    $pointer: navigation pointer 
  
                                            

Example 1
  $mapped = $url->map('index/user', '<span class="bi-chevron-right"></span>');

  var_dump($mapped);
                                            

The above returns a string similar to the html below:
    
  <a href="index">index</a> 

  <span class="bi-chevron-right"></span> 

  <a href="index/user">user</a>
    
                                            
According to the html structure above, each part of the supplied url is converted to a link which is a reflection of its parent or root link. Notice that the first link generated was index while the final url of the last link generated is index/user. The icon supplied as pointer is also used as the resolved links separator. Using the bootstrap library, the link will finally resemble the format below on web pages
  index  user 
                                            
Any string can be used as the navigation pointer of the urls as it is not necessary to use an icon. It could as well be a text or an image.

setbase
The setbase() method is used to apply a prefix to generated urls. When defined, the value supplied will be added at the beginning of all generated url.

Example
   $url->setbase('http::/localhost/app'); // supplies a prefix to all mapped urls
   
   $mapped = $url->map('index/user', '<span class="bi-chevron-right"></span>');

   var_dump($mapped);
                                    
The html string returned above will resemble the format below:
    
  <a href="http://localhost/app/index">index</a> 

  <span class="bi-chevron-right"></span> 

  <a href="http://localhost/app/index/user">user</a>
    
                                    
In the above response html format, notice that the supplied base prefix was added to the url supplied. The Window root class has a built-in static method map() for mapping urls. The window class handles the setbase() part of the Urlmapper class and just applying the directive self::map() urls can be easily mapped. This provides an easy navigation system.