I wrote my own mvc for php and it seems to work fine for me. But I am having problems getting the controller and action:
http://www.example.com/controller/action
this works fine, but as soon as small changes in the url appear, my code breaks the application. eg:
http://www.example.com/controller ? thi breaks, saying that controller?does not exist,
http://www.example.com/controller/action ? thi breaks, saying that action?does not exist,
I can’t understand why it takes ?there, and if any body knows more reliable, in order to get the right controller and action that I would like to know.
here is my code:
the entire request is 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';
}
}
source
share