Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Commit

Permalink
modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanwei9467 committed Jan 8, 2015
1 parent 561d9de commit d3438d1
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions docs/languages/zh/user-guide/modules.rst
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
.. _user-guide.modules:

Modules
模块
=======

Zend Framework 2 uses a module system to organise your main
application-specific code within each module. The Application module provided by
the skeleton is used to provide bootstrapping, error and routing configuration to
the whole application. It is usually used to provide application level
controllers for, say, the home page of an application, but we are not going to
use the default one provided in this tutorial as we want our album list to be
the home page, which will live in our own module.
Zend Framework 2 使用一个模块系统在每个模块去组织你的主应用代码.提供的应用程序模块框架用于提供引导,错误和路由配置对整个应用程序.
它通常用于提供应用程序级别的控制器,应用程序的主页, 但是我们不会使用本教程中提供的默认的,我们想要在我们的模块中构建我们的专辑列表主页.

We are going to put all our code into the Album module which will contain our
controllers, models, forms and views, along with configuration. We’ll also tweak
the Application module as required.
我们将要把包含有控制器,表单,视图,单独的配置的所有代码放进专辑模块中. 我们也会根据需要调整我们的应用程序.

Let’s start with the directories required.
让我们先从需要的目录开始.

Setting up the Album module
设置相册模块
---------------------------

Start by creating a directory called ``Album`` under ``module`` with the following
subdirectories to hold the module’s files:
在``module``目录下创建一个 ``Album`` 文件夹,用下面的子目录来保存模块中的文件:

.. code-block:: text
:linenos:
Expand All @@ -39,20 +31,15 @@ subdirectories to hold the module’s files:
/album
/album
As you can see the ``Album`` module has separate directories for the different
types of files we will have. The PHP files that contain classes within the
``Album`` namespace live in the ``src/Album`` directory so that we can have
multiple namespaces within our module should we require it. The view directory
also has a sub-folder called ``album`` for our module’s view scripts.
正如你看到的 ``Album`` 模块下有不同的目录来保存不同类型的文件. 在``src/Album``目录下,有Album的命名空间里面存放着php的类文件,
如果有需要我们可以在这个模型下有多个命名空间. 视图目录下也有一个叫做``album``的子目录来存放模块的视图文件.

In order to load and configure a module, Zend Framework 2 has a
``ModuleManager``. This will look for ``Module.php`` in the root of the module
directory (``module/Album``) and expect to find a class called ``Album\Module``
within it. That is, the classes within a given module will have the namespace of
the module’s name, which is the directory name of the module.
为了加载和配置一个模块, Zend Framework 2 有一个叫做
``ModuleManager``. 这将在模块的根目录(``module/Album``)下寻找 ``Module.php`` 期望在这个文件中能找到 ``Album\Module``类.
也就是说, 在模块的类中将有一个用模块目录名命名的命名空间.
Create ``Module.php`` in the ``Album`` module:
Create a file called ``Module.php`` under ``zf2-tutorial/module/Album``:
为``Album``模块创建 ``Module.php``文件:
在``zf2-tutorial/module/Album``目录下创建一个名称为 ``Module.php`` 的文件 :

.. code-block:: php
:linenos:
Expand Down Expand Up @@ -84,8 +71,7 @@ Create a file called ``Module.php`` under ``zf2-tutorial/module/Album``:
}
}
The ``ModuleManager`` will call ``getAutoloaderConfig()`` and ``getConfig()``
automatically for us.
``ModuleManager`` 将会为我们自动调用 ``getAutoloaderConfig()`` 和 ``getConfig()``.
Autoloading files
^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit d3438d1

Please sign in to comment.