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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.