如何组织PHP代码? [英] How to organize PHP code?

查看:55
本文介绍了如何组织PHP代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经学习了几周PHP。有了包含,PHP

脚本和HTML,我可以看到一个大而复杂的网站可以轻松地转到一个大块的混乱的文件到处。


是否有任何采用的标准,公认的建议或最好的b $ b实践如何组织所有代码?我还没有找到任何讨论此事的

网站。


有人能指点我这方面的信息吗?如果不是那么你做什么,

即如果你有条理的话?


感谢您的帮助。

I''ve been learning about PHP for a couple of weeks. With includes, PHP
scripts, and HTML I can see where a large and complex website could
easily turn in to a big hairy mess with files all over the place.

Are there any adopted standards, recognized recommendations, or best
practices on how all the code should be organized? I haven''t found any
websites that discuss this.

Can anyone point me to information on this? If not then what do you do,
i.e. if you are organized?

Thanks for your help.

推荐答案

我还没有找到一种有说服力的方式,但是阅读同样好的东西

关于最小(代码分离)和最大(代码内联)样式。


个人小件我把它们内联。

重复件我创建函数并存储在单独的文件中

使用include()时必要的,将功能组合在一起。


这就是我组织项目的方式。内联对于

显示内容很有用,计算应该在函数IMHO中完成。


希望有帮助,


Andu Turner。

On Tue,2003年9月30日17:32:40 -0400,Bruce W ... 1

< br *** @ noDirectEmail.com>写道:
I have not found one definative way, but read equally good things
about minimal (code-seperate) and maximal (code-inline) styles.

Personally for small pieces I put them inline.
For repeating pieces I create functions and store in seperate file
using include() when neccessary, grouping like functions together.

Thats pretty much how I organise my projects. Inline is useful for
display stuff and calculations should be done in functions IMHO.

Hope that helps,

Andu Turner.
On Tue, 30 Sep 2003 17:32:40 -0400, "Bruce W...1"
<br***@noDirectEmail.com> wrote:
我已经学习了几个星期的PHP。通过包含,PHP
脚本和HTML,我可以看到大型复杂网站可以轻松地将文件转移到整个地方的文件中。

关于如何组织所有代码的任何采用的标准,公认的建议或最佳实践?我还没有找到任何讨论这个问题的网站。

有人能指点我这方面的信息吗?如果没有那么你做什么,
即如果你有条理的话?

感谢你的帮助。
I''ve been learning about PHP for a couple of weeks. With includes, PHP
scripts, and HTML I can see where a large and complex website could
easily turn in to a big hairy mess with files all over the place.

Are there any adopted standards, recognized recommendations, or best
practices on how all the code should be organized? I haven''t found any
websites that discuss this.

Can anyone point me to information on this? If not then what do you do,
i.e. if you are organized?

Thanks for your help.








你可以使用模板,看看这个网站。
http://smarty.php。 net /


On Tue,2003年9月30日17:32:40 -0400,Bruce W ... 1写道:

You can use templates, have a look at this site.
http://smarty.php.net/

On Tue, 30 Sep 2003 17:32:40 -0400, Bruce W...1 wrote:
我已经学习了几周的PHP知识。通过包含,PHP
脚本和HTML,我可以看到大型复杂网站可以轻松地将文件转移到整个地方的文件中。

关于如何组织所有代码的任何采用的标准,公认的建议或最佳实践?我还没有找到任何讨论这个问题的网站。

有人能指点我这方面的信息吗?如果不是那么你做什么,
即如果你有条理?

感谢您的帮助。
I''ve been learning about PHP for a couple of weeks. With includes, PHP
scripts, and HTML I can see where a large and complex website could
easily turn in to a big hairy mess with files all over the place.

Are there any adopted standards, recognized recommendations, or best
practices on how all the code should be organized? I haven''t found any
websites that discuss this.

Can anyone point me to information on this? If not then what do you do,
i.e. if you are organized?

Thanks for your help.







" Bruce W ... 1" <峰; br *** @ noDirectEmail.com>在消息中写道

新闻:3F *************** @ noDirectEmail.com ...

"Bruce W...1" <br***@noDirectEmail.com> wrote in message
news:3F***************@noDirectEmail.com...
我一直在学习关于PHP几周。通过包含,PHP
脚本和HTML,我可以看到大型复杂网站可以轻松地将文件转移到整个地方的文件中。

关于如何组织所有代码的任何采用的标准,公认的建议或最佳实践?我还没有找到任何讨论这个问题的网站。

有人能指点我这方面的信息吗?如果不是那么你做什么,
即如果你有条理?

感谢您的帮助。
I''ve been learning about PHP for a couple of weeks. With includes, PHP
scripts, and HTML I can see where a large and complex website could
easily turn in to a big hairy mess with files all over the place.

Are there any adopted standards, recognized recommendations, or best
practices on how all the code should be organized? I haven''t found any
websites that discuss this.

Can anyone point me to information on this? If not then what do you do,
i.e. if you are organized?

Thanks for your help.




我读了一个多年以前的旧C ++书,自从编程结构类似于
之后,我已经向我提出了一些建议......其中一个是我写的任何

函数很少比屏幕截图/显示更大(即没有

需要上下/下来查看单个功能)。函数帮助你

定位错误,虽然我不是100%肯定这一点,但我相信

函数可以提高内存使用率。这是因为一旦函数

返回/完成,其分配的内存将再次释放。此规则唯一的

差异在于您的功能是否已通过数据处理

并在接近完成时返回。


其次,我正在研究一个项目,而不是内联打印

语句(例如,打印值以形成

从中恢复的字段我的数据库)我把所有的功能都放在一个单独的文件中,

包含在HTML设法开始之前。这部分是因为

标题之前发送的很多任何html都被发送 - 因此如果你想使用由PHP提供的
cookies,如果你试图在一段html

代码之后设置一个cookie你会运行错误。


因此,对于我所拥有的html文件,我还有一个单独的php文件,其中包含了
...


哦!最后 - 如果它是你的第一次编程...在你的代码中充分利用

备注语句,这样当你在几周或几个月内重新审视它时,或者b $ b时间,或者如果别人正在研究你的代码,它给你/他们一个更容易的生活,看看它应该做什么。


希望有帮助......



I read an old C++ book years ago and since the programming is structured
similar, I''ve carried some of its suggestions with me... One being any
functions I write are rarely ever larger than a screen shot/display (ie no
need to scrool up/down to view a single function). Functions help you
locate bugs and, while I am not 100% certain of this, I do believe that
functions make better memory usage. This is because once a function
returns/completes, its allocated memory is made free again. The only
difference to this rule is if your function has been passed data, processed
and returned in near completion.

Secondly, I''m working on a project at the moment and other than inline print
statements (for example, to print values in to form fields that were
restored from my database) I have all my functions in a seperate file that
gets included before HTML manages to kicks in. This is in part because of
headers which much be sent before any html is sent - thus if you want to use
cookies, delivered by PHP, if you try to set a cookie after a piece of html
code you''ll run in to errors.

Thus, for ever html file that I have, I also have a seperate php file which
gets included...

Oh! and lastly - if its your first time programming... make great usage of
remark statements in your code so when you reinspect it in weeks or months
time, or if someone else is working on your code, that it gives you/them an
easier life having to see what its supposed to be doing.

Hope that helps...


这篇关于如何组织PHP代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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