[英]PHP best design practices
Ok, have a bunch of questions that I have been thinking about the past few days. 好的,有一堆我过去几天一直在思考的问题。 Currently I have a site that is just a bunch of PHP files with MySQL statements mixed in with PHP, HTML and CSS, basically a huge mess. 目前我的网站只是一堆PHP文件,其中MySQL语句与PHP,HTML和CSS混合在一起,基本上是一团糟。 I have been tasked with cleaning up the site and have made for myself, the following requirements: 我的任务是清理网站,并为自己做了以下要求:
Saying that, this is what I know about the site as it is now: 这就是说,这就是我现在对网站的了解:
So, knowing those things I wanted to know if anyone had any tips/suggestions as to how to go about doing this with the least amount of headaches. 所以,知道那些我想知道的事情,如果有人有任何提示/建议,如何以最少的头痛去做这件事。
EDIT: Thanks for the answers, when I said no frameworks I basically meant anything that would require new syntax other than PHP, as whoever gets hired to work on this site after me will probably only know PHP. 编辑:谢谢你的答案,当我说没有框架我基本上意味着任何需要除PHP以外的新语法的东西,因为在我之后被雇用在这个网站上工作的人可能只会知道PHP。
Here's an article about how to organize your PHP project, from Rasmus Lerdorf, the architect who created the language: 这是一篇关于如何组织PHP项目的文章,来自创建该语言的架构师Rasmus Lerdorf:
http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html
Despite the popularity of OO frameworks for PHP, Rasmus advocates a less OO approach. 尽管面向PHP的OO框架很受欢迎,但Rasmus提倡采用较少的面向对象方法。 He knows more than anyone about PHP intended usage, and how to take advantage of its architecture for high-performance websites. 他比任何人都更了解PHP的用途,以及如何利用其架构来实现高性能网站。
edit: In response to the comment by @theman, I'll concede the article isn't a fine work of writing, but I think the content is important. 编辑:在回应@theman的评论时,我会承认这篇文章不是一篇很好的写作,但我认为内容很重要。 Using PHP as it was intended to be used is better than struggling against its weaknesses to make it fit an OO mold. 使用PHP本打算使用它比努力克服它的弱点以使其适合OO模具更好。
Have a look at this SO question and the answer. 看看这个问题和答案。 It's a pretty good, simple MVC design with some tips on how it can be improved. 这是一个非常好的,简单的MVC设计,提供了一些如何改进它的技巧。 If you are concerned about maintenance, then at the very least you need to seperate presentation from logic (you need a view and controller). 如果您担心维护,那么至少您需要从逻辑中分离演示文稿(您需要一个视图和控制器)。 Smarty forces that, but it is a type of framework and you'll have additional syntax to learn. Smarty强制说,但它是一种框架,你将有额外的语法来学习。
Before you jump on Rasmus' "no framework php mvc framework" bandwagon, read some of the critical comments. 在你跳过Rasmus的“无框架php mvc框架”之前,请阅读一些批评意见。 Any web application structure is a framework, and Rasmus' approach isn't the best I've seen. 任何Web应用程序结构都是一个框架,而Rasmus的方法并不是我见过的最好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.