11MVC Applications
22================
3- All the hard work behind orchestrating the operation of MVC in Phalcon is normally done by
4- :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >`. This component encapsulates all the complex
5- operations required in the background, instantiating every component needed and integrating it with the
6- project, to allow the MVC pattern to operate as desired.
3+ 在 Phalcon 中,所有复杂的MVC相关工作都是由 :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` 来完成的。该组件封装了所有复杂的后台操作,包括每一个组件的实例化,组件之间的集成等。
74
85Single or Multi Module Applications
96-----------------------------------
10- With this component you can run various types of MVC structures:
7+ 使用此组件,您可以运行不同类型的MVC结构:
118
129Single Module
1310^^^^^^^^^^^^^
14- Single MVC applications consist of one module only. Namespaces can be used but are not necessary.
15- An application like this would have the following file structure:
11+ 单MVC应用程序只包含一个module,可以使用命名空间,但不是必需的。这样的应用程序的文件结构如下:
1612
1713.. code-block :: php
1814
@@ -26,7 +22,7 @@ An application like this would have the following file structure:
2622 img/
2723 js/
2824
29- If namespaces are not used, the following bootstrap file could be used to orchestrate the MVC flow:
25+ 如果不使用命名空间,引导文件被用来协调MVC流程:
3026
3127.. code-block :: php
3228
@@ -58,7 +54,7 @@ If namespaces are not used, the following bootstrap file could be used to orches
5854 echo $e->getMessage();
5955 }
6056
61- If namespaces are used, the following bootstrap can be used:
57+ 如果使用命名空间,引导文件可以这样做:
6258
6359.. code-block :: php
6460
@@ -103,7 +99,7 @@ If namespaces are used, the following bootstrap can be used:
10399
104100 Multi Module
105101^^^^^^^^^^^^
106- A multi -module application uses the same document root for more than one module. In this case the following file structure can be used:
102+ 一个multi -module(多模块)的应用程序是指使用相同的Document Root,但有超过一个module。在这种情况下,程序的文件结构如下:
107103
108104.. code-block :: php
109105
@@ -124,7 +120,7 @@ A multi-module application uses the same document root for more than one module.
124120 img/
125121 js/
126122
127- Each directory in apps/ have its own MVC structure. A Module.php is present to configure specific settings of each module like autoloaders or custom services:
123+ 在 apps/ 目录下的每个目录都有自己的MVC结构, Module.php是每个Module特定的设置:
128124
129125.. code-block :: php
130126
@@ -178,7 +174,7 @@ Each directory in apps/ have its own MVC structure. A Module.php is present to c
178174
179175 }
180176
181- A special bootstrap file is required to load the a multi-module MVC architecture:
177+ 一个特殊的引导文件,用以载入 multi-module MVC 结构:
182178
183179.. code-block :: php
184180
@@ -250,8 +246,7 @@ A special bootstrap file is required to load the a multi-module MVC architecture
250246 echo $e->getMessage();
251247 }
252248
253- If you want to maintain the module configuration in the bootstrap file you can use an anonymous function to register the
254- module:
249+ 如果你想把配置文件完全写入到引导文件,你可以使用一个匿名函数的方式来注册 Module :
255250
256251.. code-block :: php
257252
@@ -278,16 +273,11 @@ module:
278273 )
279274 );
280275
281- When :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` have modules registered, always is
282- necessary that every matched route returns a valid module. Each registered module has an associated class
283- that offers functions to set the module itself up. Each module class definition must implement two
284- methods: registerAutoloaders() and registerServices(), they will be called by
285- :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` according to the module to be executed.
276+ 当 :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` Module注册后,每个匹配的route都必须返回一个有效的module。注册的module都有一个相关的类,用于设置module本身提供的功能。每个module类都必须实现 registerAutoloaders() 和 registerServices() 这两个方法,:doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` 将调用它们执行要执行的module。
286277
287- Understanding the default behavior
278+ 了解默认行为
288279----------------------------------
289- If you've been following the :doc: `tutorial <tutorial >` or have generated the code using :doc: `Phalcon Devtools <tools >`,
290- you may recognize the following bootstrap file:
280+ 如果你一直关注 :doc: `tutorial <tutorial >` 或 使用 :doc: `Phalcon Devtools <tools >` 生成过代码,你可能会熟悉以下的引导文件:
291281
292282.. code-block :: php
293283
@@ -310,15 +300,15 @@ you may recognize the following bootstrap file:
310300 echo "PhalconException: ", $e->getMessage();
311301 }
312302
313- The core of all the work of the controller occurs when handle() is invoked:
303+ 所有控制器工作的核心是 handle()方法被调用:
314304
315305.. code-block :: php
316306
317307 <?php
318308
319309 echo $application->handle()->getContent();
320310
321- If you do not wish to use :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >`, the code above can be changed as follows:
311+ 如果您不希望使用 :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` ,上面的代码可以修改如下:
322312
323313.. code-block :: php
324314
@@ -364,14 +354,11 @@ If you do not wish to use :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Ap
364354 // Print the response
365355 echo $response->getContent();
366356
367- Although the above is a lot more verbose than the code needed while using :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >`,
368- it offers an alternative in boostraping your application. Depending on your needs, you might want to have full control of what
369- should be instantiated or not, or replace certain components with those of your own to extend the default functionality.
357+ 尽管上面的代码显得比使用 :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` 罗唆,但它提供了一种替代bootstrap文件的方式。根据你的需要,你可能希望完全掌握哪些类应该被实例化,或使用自己的组件来扩展默认的功能。
370358
371359Application Events
372360------------------
373- :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` is able to send events to the :doc: `EventsManager <events >`
374- (if it is present). Events are triggered using the type "application". The following events are supported:
361+ :doc: `Phalcon\\ Mvc\\ Application <../api/Phalcon_Mvc_Application >` 能够将事件发送到 :doc: `EventsManager <events >`,事件管理器通过触发 "application"来实现,支持以下的事件:
375362
376363+---------------------+--------------------------------------------------------------+
377364| Event Name | Triggered |
@@ -385,7 +372,7 @@ Application Events
385372| afterHandleRequest | After execute the dispatch loop |
386373+---------------------+--------------------------------------------------------------+
387374
388- The following example demonstrates how to attach listeners to this component:
375+ 下面的示例演示如何在此组件上添加监听器:
389376
390377.. code-block :: php
391378
@@ -402,7 +389,7 @@ The following example demonstrates how to attach listeners to this component:
402389 }
403390 );
404391
405- External Resources
392+ 相关资源
406393------------------
407394
408395* `MVC examples on Github <https://github.com/phalcon/mvc >`_
0 commit comments