Zend Framework 应用程序的默认模块化目录结构

发布于 2024-08-05 00:54:18 字数 639 浏览 3 评论 0原文

我知道手册中的 Zend Framework 模块化应用程序的默认目录结构。

/application
  /controllers
  /modules
    /admin
      /controllers
      /views
  /views
  /configs
/www
  index.php

但我想知道为什么我要这样做。在 /application 中拥有默认模块,在 /application/modules/:moduleName 中拥有其他模块确实很重要。这更像是一个讨论问题,而不是一个帮助我的问题。

像这样的目录结构有什么优点和缺点:

/application
  /modules
    /admin
      /controllers
      /views
    /default
      /controllers
      /views
  /configs
/www
  index.php

从我的角度来看,唯一的缺点是它在默认/手册中不是这样写的。我看不到其他的了。我错过了什么吗?

更重要的是 - 我认为这个结构应该是任何新的 ZF 应用程序的默认结构。我想知道为什么 Zend 开发人员不使用它。

I'm aware of default directory structure for Zend Framework modular applications that is in the manual.

/application
  /controllers
  /modules
    /admin
      /controllers
      /views
  /views
  /configs
/www
  index.php

But I'm wondering why should I do it this way. It really sux to have the default module in /application and other modules in /application/modules/:moduleName. This is more of a discussion question than a help-me question.

What are the pros and cons of having directory structure like this:

/application
  /modules
    /admin
      /controllers
      /views
    /default
      /controllers
      /views
  /configs
/www
  index.php

From my point of view the only disadvantage is that it's not written like this in default / in manual. I can't see any other. Am I missing something?

Even more - I think that this structure should be default structure for any new ZF application. And I wonder why Zend developers doesn't use it.

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

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

发布评论

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

评论(5

春庭雪 2024-08-12 00:54:18

实际上,您建议的目录结构非常适合大型且复杂的应用程序。

Magento 是当今世界上最好的开源电子商务解决方案,已在 Zend 框架中进行编码,并使用与您建议的类似的目录布局,这样就可以非常轻松地扩展和添加新模块以及管理旧模块。

同样,对于简单的应用程序和学习 Zend,我建议每个人都坚持默认的目录结构。

Actually your proposed directory structure is more than appropriate for large and complex applications.

Magento which is world's best Open Source e-commerce solution today has been coded in Zend framework and uses similar directory layout as you propose, this way its very easy to extend and add new modules and manage old ones.

Again for simple apps and for learning Zend I would suggest everyone to stick to the default directory structure.

默嘫て 2024-08-12 00:54:18

我想这种方式是因为:

  • 有一个默认结构,当应用程序中没有模块时使用该结构(即只有一个默认模块——这意味着不需要“默认”目录)
  • ,然后,您可以添加模块;无需修改现有结构。

我想,这是一个和其他解释一样好的解释。

不过,如果开发一个包含多个模块的应用程序,并且从一开始就知道这一点,我可能会采用您提议的结构,而不是默认的结构 ^^

这样,事情会更清楚,在我的意见——我认为这没有任何问题!

(事实上,我曾经这样做过,很久以前,并且没有遇到任何麻烦 - 但这不是一个“完整”的应用程序;更多的是原型......)

I suppose this way is because :

  • there is a default structure, that is used when there is no module in an application (ie, only a default module -- which means no need for a "default" directory)
  • and, then, you can add modules ; without having to modify the existing structure.

It's an explanation as good as any other, I suppose.

Still, if developping an application that will contain several modules, and knowing this from the start, I'd probably go with the kind of struture you are proposing, and not the default one ^^

Things would be more clear that way, in my opinion -- and I don't see any problem with that !

(In fact, I've that way once, quite some time ago, and have not met any trouble -- but this was not a "complete" application ; more a prototype... )

是你 2024-08-12 00:54:18

实际上,这是 http://framework.zend 上详细介绍的选项之一.com/manual/en/zend.controller.modular.html

你的方式听起来不错,ZF 的重点是你可以选择如何自己管理事物。优点之一是代码稍微少一些。在 Zend 的默认方法中,您需要使用这个:

$front = Zend_Controller_Front::getInstance();
$front->addControllerDirectory('/path/to/application/controllers', 'default');
$front->addModuleDirectory('/path/to/application/modules');

而在您描述的方法中:

$front = Zend_Controller_Front::getInstance();
$front->addModuleDirectory('/path/to/application/modules');

就是您所需要的。

Zend 方法的优点之一是,如果您不需要模块,则无需运行 addModuleDirectory() 方法。按照您的方法,这始终需要运行,可能会产生少量开销。

此页面 http://framework.zend.com/manual/en/ project-struct.project.html 声明默认控制器目录“在应用程序目录内提供了启动简单项目以及启动具有全局控制器/模型/视图的模块化项目的最佳布局。”

我猜 Zend 的观点是,这既适用于仅具有默认模块的简单站点,也适用于具有多个模块的更复杂站点。不难找出 module/ 目录中的更多模块。但归根结底,这是个人喜好。

Actually that is one of the options detailed on http://framework.zend.com/manual/en/zend.controller.modular.html

Your way sounds fine and the point of ZF is you can choose how to manage things yourself. One advantage is slightly less code. In Zend's default approach you'd need to use this:

$front = Zend_Controller_Front::getInstance();
$front->addControllerDirectory('/path/to/application/controllers', 'default');
$front->addModuleDirectory('/path/to/application/modules');

Whereas in the approach you describe:

$front = Zend_Controller_Front::getInstance();
$front->addModuleDirectory('/path/to/application/modules');

Is all you need.

One advantage of Zend's approach is if you don't need modules, then there's no need to run the addModuleDirectory() method. With your approach this would always need to be run, potentially creating a small overhead.

This page http://framework.zend.com/manual/en/project-structure.project.html states having the default controllers directory "inside the application directory provides the best layout for starting a simple project as well as starting a modular project that has global controllers/models/views."

I guess Zend's point of view is that this works for both simple sites with only a default module and more complex ones with multiple modules. It's not hard to work out further modules are in the modules/ directory. But at the end of the day, it's personal preference.

苹果你个爱泡泡 2024-08-12 00:54:18

我正在努力解决同样的问题。但我没有成功地正确设置它......
我为什么要使用它是因为模块化结构与 Zen_Application 结合,实例化了一个 Module_Bootstrapper,它自动在 /application/module/name/forms 中注册命名空间(以及控制器、视图、模型等)。

我遇到的唯一问题是摆脱“默认”模块:

您可以在 Zend 论坛上找到该主题:http://forums.zend.com/viewtopic.php?f=69&t=2394&start=0

希望它能得到回答了,不然我会把它贴在这里。

I'm strugling with the same problem. But i'm not succeeding in setting this up properly...
Why I want to use this is because the modular structure, combined with Zen_Application, instantiates a Module_Bootstrapper which registeres the namespaces in /application/module/name/forms (and controllers, views, models, etc...) automaticly.

The only problem i'm having is getting rid of the 'default' module :S

you can find the topic on Zend Forums here: http://forums.zend.com/viewtopic.php?f=69&t=2394&start=0

Hopefully it'll get answered, ot i'll post it up here.

雾里花 2024-08-12 00:54:18

您可以在这里找到您想要的架构: http://www.osebboy.com/blog/ zend-framework-modules/

You can find your desired architecture here: http://www.osebboy.com/blog/zend-framework-modules/

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