Jump to content

Splitting URL into array in bootstrap file


spaze

Recommended Posts

Hello all,

 

I am working on my own framework for certain reasons and just wanted to know what is the best way to split given URL into an array from which I would build the function.

 

So far I have:

 

$service_dirs = explode('/', $_SERVER["REQUEST_URI"]);

$controller, $action, $obj = '';
  
if ($service_dirs) {
  if ( $service_dirs[2] ) {
    $controller = $service_dirs[2];
  }
  if ( $service_dirs[3] ) {
    $action = $service_dirs[3];
  }
  if ( $service_dirs[4] ) {
    $obj = $service_dirs[4];
  }
}

 

What would be a better approach to this. I have a bootstrap file index.php to which all traffic is directed. Then the index.php calls for certain controllers based on the given URL:

 

www.mydomain.com/view/user/1234

 

In the above example I would call the view controller and userAction with userid 1234.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.