Possible Duplicate:
CMS Routing in MVC
I want to implement the MVC design structure and currently struggeling with an good solution to parse requested views.
In my routing file, I have following code:
public function parseRequestedView() {
$this->ressource_requested = explode('/', trim($_GET['view'], '/'));
// e.g.: http://www.foo.com/article/{id}/comments/show
if (!empty($this->ressource_requested[3])) {
// Format: [0] viewpoint (article), [1] child (comments), [2] action (show), [3] reference ({id}),
// [4] additional information (from $_POST)
return array($this->ressource_requested[0], $this->ressource_requested[2], $this->ressource_requested[3],
$this->ressource_requested[1], $_POST);
// e.g.: http://www.foo.com/article/{id}/show
} elseif (!empty($this->ressource_requested[2])) {
return array($this->ressource_requested[0], NULL, $this->ressource_requested[2], $this->ressource_requested[1],
$_POST);
// e.g.: http://www.foo.com/archive/show
} else {
return array($this->ressource_requested[0], NULL, $this->ressource_requested[1], NULL, NULL);
}
}
The idea is, no matter what a visitor types into the browser, the function parses the request and always returns the same formatted array/output. The first segment of the URL following the hostname is always the main viewpoint (e.g.: article). In the end, I am including the view through another function called includeTemplateFile(). The files have this naming convention:
viewpoint.child.action.template.php
e.g.: article.comments.show.template.php
My question is now: Is there a more elegant solution? I read some of the turorials/articles (e.g.: http://johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one) regarding this topic, but I do not like most solutions since they are not well designed.
Here is the content of the .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?view=$1 [L,QSA]
Thanks in advance.