我的框架应该有多少目录分隔?

发布于 2024-09-08 10:04:00 字数 1321 浏览 4 评论 0原文

我一直在为我的 PHP MVC 框架尝试一堆不同的目录结构。在执行此操作时,我想到了将应用程序的不同部分彼此分开的几个原因。

例如,假设这是我当前的结构:

- index.php
- private/
    - application/
        - ... (MVC stuff. Irrelevant I think...)
    - config/
        - config.php
    - framework/
        - bootstrap.php
        - includes/
        - library/
            - ... (Framework classes)
    - libraries/
        - Zend/
        - PEAR/
 - public/
     - css/
     - images/

按照我的方式,我只需覆盖 /private/framework/ 目录即可更新框架,这不会影响用户的框架配置/private/config/,或 /private/libraries/ 中的第三方库。

/index.php 文件几乎纯粹用于加载 /private/framework/bootstrap.php 文件,这意味着更新 /private/framework/ 目录还将更新主引导文件(使我不必更新 /index.php 文件,该文件将保持原样,因为其中没有太多内容)。

此外,应用程序也与框架相关的所有内容分开,因此用户可以在需要时切换/更改/更新其应用程序,而不必担心其他目录。

关于将目录彼此分开以使它们更易于更新,我是否走在正确的道路上?

我在一些框架中看到它们的框架目录中有 /private/libraries//private/application/ 目录......但这在我看来就像如果需要的话很难更新到新版本的框架。或者我的想法是错误的?

您可以看到我以前的目录结构 如果您有兴趣,请点击此处。我的新问题有点不同(希望更好......),就像我的问题一样,所以我认为有必要发布一个新问题。

这不是我希望的那么小问题,但是啊,好吧! ;)

提前致谢 =)

I've been trying a bunch of different directory structures for my PHP MVC framework. While doing this, I thought of a few reasons to separate different parts of the application from each other.

For instance, let's say this is my current structure:

- index.php
- private/
    - application/
        - ... (MVC stuff. Irrelevant I think...)
    - config/
        - config.php
    - framework/
        - bootstrap.php
        - includes/
        - library/
            - ... (Framework classes)
    - libraries/
        - Zend/
        - PEAR/
 - public/
     - css/
     - images/

The way I have it, I can update the framework simply by overwriting the /private/framework/ directory, which won't affect the user's framework configuration in /private/config/, or the 3rd party libraries in /private/libraries/.

The /index.php file is used almost purely to load the /private/framework/bootstrap.php file, which will mean updating the /private/framework/ directory will also update the main bootstrapping file (Saving me from having to update the /index.php file, which will stay as is, as there's not much at all in it).

Also, the application is separate from everything to do with the framework too, so the user can switch/change/update their applications when needed without having to worry about other directories.

Am I on the right track here with regards to separating the directories from one another to make them easier to update?

I've seen in some frameworks that they have both their /private/libraries/ and /private/application/ directories inside their framework directory... but this seems to me like it would be hard to update to a newer version of the framework if needed. Or am I thinking about it the wrong way?

You can see my previous dir structure here if you're interested. My new one is a little different (hopefully better...), as is my question, so I thought it warranted the posting of a new question.

It's not as small of a question as I would have hoped, but ah well! ;)

Thanks in advance =)

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

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

发布评论

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

评论(1

℉絮湮 2024-09-15 10:04:00

我建议将框架代码与应用程序代码分开。框架应位于一个顶级目录下,而应用程序应位于不同的顶级目录下。

其实...我建议你看看CakePHP使用的目录结构。

I would suggest separating framework code from application code. The framework should be under one top-level directory and the application under a different one.

Actually... I suggest you look at the directory structure used by CakePHP.

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