I’m creating a custom MVC framework, but I’m stuck with some URL definitions in the view files. I have this piece of code which lets me use SEO friendly links:
$requestURI = explode('/', $_SERVER['REQUEST_URI']);
$scriptName = explode('/', $_SERVER['SCRIPT_NAME']);
for( $i = 0; $i < sizeof($scriptName); $i++)
{
if( $requestURI[$i] == $scriptName[$i])
{
unset($requestURI[$i]);
}
}
$command = array_values($requestURI);
if( sizeof($command) === 0 OR sizeof($command) === 1)
{
init_controller_class($config['default_controller'], $config['default_entry']);
}
elseif( sizeof($command) >= 2)
{
init_controller_class($command[0], $command[1]);
}
My view file:
<div class="container">
<div class="header">
<ul class="menu">
<li><a href="#">Home</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">About µMVC</a></li>
</ul>
</div>
</div>
The URL for the landing page is http://mvc.localhost:8888/welcome/index. How do I set the URLs in this menu?
Because, if I insert <li><a href="welcome/about">About µMVC</a></li>, it will redirect to http://mvc.localhost:8888/welcome/welcome/about and obviously my script will terminate, ’cause function welcome with parameter value 'about' does not exist in the controller welcome. How to eliminate this problem?
use absolute paths in your links, like /welcome/about