Web 上的路由 MVC
我想知道是否有人可以为我提供一些关于如何改进应用程序每个“部分”的路由(和/或架构)的建议。 (我正在用 PHP5 编写,并尝试使用严格的 MVC)
基本上,我有一个应用程序的通用索引页面,它将喷出 jquery 和 css 等样板内容,并且它还会生成主要导航整个站点,但我不确定将“主菜单”项(超链接)与其关联的控制器连接的最佳方法。到目前为止,我一直将字符串附加到 url 中,并使用“switch”语句通过从“$GET[]”中提取字符串来分支到正确的控制器(和视图),以让它执行相应的代码行动。例如,如果我有一个用于客户数据的基本 CRUD 系统,则编辑客户详细信息的 URL 将类似于“www.example.com/index.php?page=customer&action=edit&id=4”。
我担心这样做会存在安全问题,并且我不确定在用户单击链接后是否有其他方法可以将主“index.php”文件分支到每个操作的正确控制器。
使用 mod_rewrite 来伪装控制器名称会更好吗?或者创建一个与 ASP MVC 框架类似的系统,其中有一个单独的路由系统,其中每个 url 都会被过滤以获取关联的控制器?
干杯!
I was wondering if anyone could possibly provide me some advice on how i could improve the routing (and/or architecture) to each 'section' of my application. (I'm writing in PHP5, and trying to use strict MVC)
Basically, I have a generic index page for the app, and that will spew out boilerplate stuff like jquery and the css etc. and it also generates the main navidation for the entire site, but i'm unsure about the best approach to connect the 'main menu' items(hyperlinks) with their associated controllers. Up until now I have been appending strings into the url and using a 'switch' statement to branch to the correct controller(and view) by extracting the strings back out of '$GET[]' to let it execute the code for the corrosponding action. for instance if i had a basic crud system for customer data, the url to edit a customers details would look like 'www.example.com/index.php?page=customer&action=edit&id=4'.
I'm worried that there is a security concern by doing it this way, and i'm not sure of an alternative to branch the main 'index.php' file to the correct controller for each action once the user has clicked the link.
Would it be better to use mod_rewrite to disguise the controllers names? or to create a similar system to the ASP MVC framework, where there is a seperate routing system where each url is filtered to get the associated controller?
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里回答我自己的问题..
我最终发现CodeIgniter(PHP)中的路由正是我所寻找的。即使您不想使用 codeIgniter,即使您想设计自己的框架,它似乎也是学习一些东西的好资源。
answering my own question here..
I eventually figured out that the routing in CodeIgniter (PHP) does exactly what i was looking for. even if you don't want to use codeIgniter, it seems to be a good resource to learn some things anyway even if you want to design your own framework.