可能重复:
CMS路由在MVC
我想实现MVC设计结构,目前有很好的解决方案来解析请求的意见struggeling。
在我的路由文件,我有下面的代码:
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);
}
}
我们的想法是,不管什么类型的访问者在浏览器中,函数解析请求,总是返回相同的格式化阵列/输出。 主机名以下URL的第一部分始终是主要的观点(如:文章)。 最后,我包括通过()调用includeTemplateFile的另一功能的视图。 该文件有这样的命名约定:
viewpoint.child.action.template.php
e.g.: article.comments.show.template.php
我的问题是现在:有没有更好的解决方案? 我看了一些turorials /文章:(例如http://johnsquibb.com/tutorials/mvc-framework-in-1-hour-part-one关于这个话题),但我不喜欢大多数的解决方案,因为他们不精心设计的。
下面是.htaccess文件的内容:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?view=$1 [L,QSA]
提前致谢。