在整个网页上使用一个文件的优缺点? [英] Pros and cons of using one file for entire webpage?

查看:67
本文介绍了在整个网页上使用一个文件的优缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定该如何表达,但我会尝试一下.
我最近开始用面向对象的PHP编写我的投资组合,我想知道是否根据最佳实践使用单个页面,其中页面的内容取决于SQL数据和$ _GET变量?

I'm not sure how I should express this, but I'll give it a try.
I recently started coding my portfolio in object-oriented PHP and I'm wondering if it's according to best practices to use a single page where the content changes depending on SQL data and the $_GET variable?

如果是/不是,为什么?

If so/not, why?

看看我的下一篇文章,更深入的细节.

Take a look at my next post, more in-depth details.

推荐答案

您是否在询问使用前端控制器模式,哪个文件可满足您的所有请求?通常,这是通过index.php和mod_rewrite完成的,它获取所有请求,并将其余URL作为查询字符串中的参数提供给它.

Are you asking about using the front controller pattern, where a single file serves all of your requests? Often this is done with an index.php and mod_rewrite getting all of the requests with the rest of the URL being given to it as a parameter in the query string.

http://www.onlamp.com /pub/a/php/2004/07/08/front_controller.html

我倾向于建议将此模式用于应用程序,因为它为您提供了一个位置来处理诸如身份验证之类的事情,并且通常您需要在更紧密的层次上集成事物,其中将新功能注册为类通过某种机制与控制器进行交互非常有意义.

I would tend to recommend this pattern be used for applications, because it gives you a single place to handle things like authentication, and often you'll need to integrate things at a tighter level where having new features be classes that are registered with the controller via some mechanism makes a lot of sense.

对其他人提到的URL的担忧并不是很准确,因为URL结构和文件结构之间没有真正的关系,除非您使用的是古老的网站构建技术.大量的apache功能基于以下概念:文件/目录结构和URL结构是不同的概念(别名模块,重写模块,内容协商等等)

The concerns about the URLs others have mentioned aren't really accurate, because there is no real relationship between URL structure and file structure, unless you're using ancient techniques of building websites. A good chunk of apache functionality is based on the concept that file/directory structure and URL structure are distinct concepts (alias module, rewrite module, content negotiation, so on and so forth)

这篇关于在整个网页上使用一个文件的优缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆