1

为什么在 Modules/ 和 Modules/Application/src 中有 zf2 Application 文件夹?我的意思是......为什么不是结构模块/应用程序/src/控制器等......?

4

2 回答 2

2

您可以找到新 zf2 结构的详细信息http://akrabat.com/zend-framework-2/modules-in-zf2/

由于我们使用的是 PHP 5.3,我们希望 src 文件夹中的类将被命名空间。默认情况下,模块的主名称假定为其主命名空间,在本例中为 Simple。为了使自动加载更简单并遵循 PSR-0 约定,我们在 src 中创建 Simple 命名空间文件夹。这意味着 SimpleController 类的命名空间是文件 src/Simple/Controller/SimpleController.php 中的 Simple\Controller。

这显然是更简单的模块之一,并且 src/Simple 文件夹可能还有其他文件夹,例如 Model、Form 等。此外,视图文件夹可能会有更多用于其他控制器的子文件夹。

于 2012-10-18T02:36:42.993 回答
1

Modules are intended to be single-purpose, reusable containers of code. As such, they will contain everything they need to accomplish that task -- which may (or may not!) include controllers, models, public assets, configuration, view templates, and more.

In order to keep the various pieces semantically grouped, each has its own subfolder in the module. Source PHP code goes in "src", and the code in that directory should follow PSR-0 naming conventions - and thus you'll see the module namespace repeated there. Configuration goes in "config", view templates in "view", public assets in "public", and so on.

That said, you're free to organize your modules however you want, so long as its Module class is discoverable, and it can indicate how to autoload classes and provide configuration to the MVC. The structure you see in the ZendSkeletonApplication and ZendSkeletonModule, however, is recommended as it's the result of a lot of brainstorming within the community, and provides clean semantics for each type of file provided.

于 2012-10-19T03:36:34.663 回答