从分离 css、phpfles 和数据库的意义上来说,PHP 编码的标准是什么

发布于 2024-07-30 12:45:20 字数 76 浏览 2 评论 0原文

给我最好的 PHP 编码标准方法。 在哪里存储我的 css、php、图像等。如何分隔我的文件夹,有多少个文件夹以及该文件夹的名称是什么?

Give me the best standard way of coding in PHP. where to store my css, php, images etc. How to separate my folders, How many folders and whats the name of that folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

转身泪倾城 2024-08-06 12:45:20

没有标准。 PHP 是一种语言,而不是一个框架,与任何语言一样,您可以按照您认为合适的方式组织您的项目。

然而,有一些用 PHP 编写的优秀框架,具有目录结构并提供工具等。例如,Cake PHP代码点火器

There is no standard. PHP is a language, not a framework, and as with any language, you can organize your project however you see fit.

However, there are some great frameworks written in PHP that have a directory structure and provide tools, etc. For example, Cake PHP and Code Igniter.

戏蝶舞 2024-08-06 12:45:20
project/web          # web root
project/web/styles   # CSS files
project/web/scripts  # JavaScript or other script files
project/web/images   # images
project/lib          # non-web-accessible code libraries
project/bin          # executables (including utility scripts)
project/web          # web root
project/web/styles   # CSS files
project/web/scripts  # JavaScript or other script files
project/web/images   # images
project/lib          # non-web-accessible code libraries
project/bin          # executables (including utility scripts)
紫竹語嫣☆ 2024-08-06 12:45:20

没有最好或标准的方法 - 这正是您可以从项目工作经验中获得的知识 - 在开始编程之前它不是您需要的东西 - 我什至建议将所有内容都保存在同一个文件夹中如果它是一个只有几个文件的小应用程序。 确实,随着时间和经验的积累,你会找到自己的方法的。

There is no best or standard way - that's the exactly kind of knowledge that you can gain from experience of working on projects - it is not something essential that you need before you can start programming - I would even suggest to keep all in the same folder if it's a small app with just couple of files. Really, you'll get your ways with time and experience.

对风讲故事 2024-08-06 12:45:20

您假设有最好的方法来做到这一点,但实际上没有。 这完全取决于您的应用程序架构和个人喜好。

我可以给您一些通用提示:

  • 合理地组织您的公共 Web 文件夹。 有一个用于图像的 images/ 目录、一个用于 CSS 的 css/ 目录和一个用于 javascript 的 js/ 目录。 代码的组织将取决于您的项目架构。
  • 如果您使用的是 OO 架构,则可以组织您的代码文件,使它们位于 Web 根目录之外,这样,如果您的 Web 服务器由于配置错误而停止正确呈现 PHP(这种情况确实发生),那么这将为您提供额外的安全层。
  • 除非有充分的理由,否则图像不应存储在数据库中。

You are assuming that there is a best way to do that, and there isn't. It is completely dependent on your application architecture and personal preference.

I can give you a couple of generic hints:

  • Organize your public web folder sanely. Have an images/ directory for images, a css/ directory for CSS, and a js/ directory for javascript. Organization of code will depend on your project architecture.
  • If you are using an OO architecture, it's possible to organize your code files so that they are outside of the web root, which gives you an added layer of security should your web server stop rendering PHP properly due to a misconfiguration (it happens).
  • Images should not be stored in a database unless you have a good reason to do so.
待"谢繁草 2024-08-06 12:45:20

我通常做的就是下一个:

-Main php files
-private
  |_private web zone files
-images
  |_image files
-flash
  |_flash files
-script
  |_javascript files
-css
  |_css files

儿子

希望我能帮助你

What I use to do is the next:

-Main php files
-private
  |_private web zone files
-images
  |_image files
-flash
  |_flash files
-script
  |_javascript files
-css
  |_css files

and son on

hope I've helped you

路还长,别太狂 2024-08-06 12:45:20

我不确定“最佳标准”,因为我认为你会发现它是
很大程度上是主观的,并且取决于其他因素,例如您所使用的任何框架
使用和您的项目的规模。

但是,我倾向于坚持以下约定:-

  • 图像 - 常规应用程序图像
  • 库 - 类文件、库文件、依赖项(通常分为许多
    包含库名称的子文件夹,例如 lib/events/employee/)。
    像这样相当逻辑地构建事物需要使用 __autoload()
    在加载文件时非常方便。
  • 控制器 - 控制器文件
  • js - Javascript 文件
  • 样式 - 样式表
  • 测试 - 单元测试
  • 模板 - 根据您的应用程序再次捆绑到各种子文件夹中
    布局。
  • tmp - 摩泽尔的东西、垃圾、原木。

我注意到这些天捆绑 js/styles/images 文件夹的约定
进入他们自己的“公共”(rails)或“静态”(django)文件夹,这些文件夹也可能是
更好。

I'm not sure about the "best standard" because I think you'll find it is
largely subjective and dependent on other factors e.g. any frameworks you're
using and the size of your project.

However, I've tended to stick with the following convention:-

  • images - General app images
  • lib - Class files, library files, dependencies (usually broken down into many
    sub folders containing the libraries name e.g. lib/events/employee/).
    Structuring things fairly logically like this makes the use of __autoload()
    quite handy when it comes to loading your files in.
  • controller - Controller files
  • js - Javascript files
  • styles - Stylesheets
  • tests - Unit tests
  • templates - Again bundled into various subfolders depending on your apps
    layout.
  • tmp - Moselle nous stuff, junk, logs.

I've noticed the conventions these days to bundle the js/styles/images folder
into their own 'public' (rails) or 'static' (django) folders which might also be
nicer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文