I wrote my own mvc for php, and it seems to be working fine for me. But i am having trouble with getting the controller and the action:
http://www.example.com/controller/action
this works fine but as soon as there are small changes to the url my code breaks appart. for example:
http://www.example.com/controller? thi breaks, saying the controller?
doesn't exist,
http://www.example.com/controller/action? thi breaks, saying the action?
doesn't exist,
i can't figure out why it takes the ?
in there and if any body know a more robust to get the correct controller and action i would love to know.
here is my code:
all the request are redirected to the same index.php page using .htaccess
class Framework {
....
private function setup() {
$uri = (isset($_SERVER['REQUEST_URI']))?$_SERVER['REQUEST_URI']: false;
$query = (isset($_SERVER['QUERY_STRING']))?$_SERVER['QUERY_STRING']: '';
$url = str_replace($query,'',$uri);
$arr = explode('/',$url);
array_shift($arr);
$this->controller =!empty($arr[0])?$arr[0]:'home';
$this->action = isset($arr[1]) && !empty($arr[1])?$arr[1]:'index';
}
}