Skip to content

Commit 27ee98f

Browse files
committed
applications,routing,tags,index
1 parent 23db9f1 commit 27ee98f

File tree

4 files changed

+68
-102
lines changed

4 files changed

+68
-102
lines changed

zh/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Phalcon不只是性能优越,我们的目标是让它强大而且易于使用!
2929

3030
本文档的中文地址存放在 http://phalcon.5iunix.net
3131

32-
Github上的地址为: https://github.com/netstu/phalcondocs ,您如果发现有些地方译的有些操蛋,烦请你clone它,并完善她。
32+
Github上的地址为: https://github.com/netstu/phalcondocs ,您如果发现有些地方译的有些操蛋,烦请你fork它,并完善她。
3333

3434
目录
3535
-------------

zh/reference/applications.rst

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
MVC 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

85
Single or Multi Module Applications
96
-----------------------------------
10-
With this component you can run various types of MVC structures:
7+
使用此组件,您可以运行不同类型的MVC结构:
118

129
Single 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

371359
Application 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>`_

zh/reference/routing.rst

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
Routing
2-
=======
3-
The router component allows defining routes that are mapped to controllers or handlers that should receive
4-
the request. A router simply parses a URI to determine this information. The router has two modes: MVC
5-
mode and match-only mode. The first mode is ideal for working with MVC applications.
1+
路由器(Routing)
2+
=============================
3+
router组件允许定义用户请求对应到哪个控制器或Action。router解析 URI 以确定这些信息。路由器有两种模式:MVC模式和匹配模式(match-only)。第一种模式是使用MVC应用程序的理想选择。
64

75
Defining Routes
86
---------------
9-
:doc:`Phalcon\\Mvc\\Router <../api/Phalcon_Mvc_Router>` provides advanced routing capabilities. In MVC mode,
10-
you can define routes and map them to controllers/actions that you require. A route is defined as follows:
7+
:doc:`Phalcon\\Mvc\\Router <../api/Phalcon_Mvc_Router>` 提供了一套先进的路由功能。在MVC模式中,你可以自定义路由规则,对应到你需要的 controllers/actions 上。路由的定义如下:
118

129
.. code-block:: php
1310
@@ -36,14 +33,9 @@ you can define routes and map them to controllers/actions that you require. A ro
3633
3734
$router->handle();
3835
39-
The method add() receives as first parameter a pattern and optionally a set of paths as second parameter.
40-
In this case if the URI is exactly: /admin/users/my-profile, then the "users" controller with its action "profile"
41-
will be executed. Currently, the router does not execute the controller and action, it only collects this
42-
information to inform the correct component (ie. :doc:`Phalcon\\Mvc\\Dispatcher <../api/Phalcon_Mvc_Dispatcher>`)
43-
that this is controller/action it should to execute.
36+
add() 方法接收两个参数,第一个参数是一个匹配字符串,第二个参数为一组可选的路径。在这种情况下,URI /admin/users/my-profile, "users"代表控制器,"profile"代表Ation。目前,该路由器不并不执行控制器和Action,只为组件(如: :doc:`Phalcon\\Mvc\\Dispatcher <../api/Phalcon_Mvc_Dispatcher>`) 收集信息,然后由分发器决定是否立即执行。
4437

45-
An application can have many paths, define routes one by one can be a cumbersome task. In these cases we can
46-
create more flexible routes:
38+
应用程序可能有很多个不同的路径,如果一个一个的定义路由的话,会非常麻烦。在这种情况下,我们可以使用更灵活的方式创建route:
4739

4840
.. code-block:: php
4941
@@ -62,8 +54,7 @@ create more flexible routes:
6254
)
6355
);
6456
65-
In the example above, using wildcards we make a route valid for many URIs. For example, by accessing the
66-
following URL (/admin/users/a/delete/dave/301) then:
57+
在上面的例子中,我们使用通配符来匹配路由。例如,通过访问URL (/admin/users/a/delete/dave/301) ,解析为:
6758

6859
+------------+---------------+
6960
| Controller | users |
@@ -75,17 +66,11 @@ following URL (/admin/users/a/delete/dave/301) then:
7566
| Parameter | 301 |
7667
+------------+---------------+
7768

78-
The method add() receives a pattern that optionally could have predefined placeholders and regular expression
79-
modifiers. All the routing patterns must start with a slash character (/). The regular expression syntax used
80-
is the same as the `PCRE regular expressions`_. Note that, it is not necessary to add regular expression
81-
delimiters. All routes patterns are case-insensitive.
69+
add()方法接收一个模式,可选择使用预定义占位符和正则表达式修饰符。所有的路由模式必须以斜线字符(/)开始。正则表达式语法使用与 `PCRE regular expressions`_ 相同的语法。需要注意的是,不必要添加正则表达式分隔符。所有的路由模式是不区分大小写的。
8270

83-
The second parameter defines how the matched parts should bind to the controller/action/parameters. Matching
84-
parts are placeholders or subpatterns delimited by parentheses (round brackets). In the above example, the
85-
first subpattern matched (:controller) is the controller part of the route, the second the action and so on.
71+
第二个参数定义了如何将匹配部分绑定到controller/action/parameters。匹配部分是占位符或团圆括号中的子模式。另外,在上述的例子中,第一个子模式匹配(:controller),是route中控制器部分,第二个是action,等。
8672

87-
These placeholders help writing regular expressions that are more readable for developers and easier
88-
to understand. The following placeholders are supported:
73+
这些占位符使用正则表达式,更易读,更容易为开发人员理解。支持以下占位符:
8974

9075
+--------------+---------------------+--------------------------------------------------------------------+
9176
| Placeholder | Regular Expression | Usage |
@@ -103,8 +88,7 @@ to understand. The following placeholders are supported:
10388
| /:int | /([0-9]+) | Matches an integer parameter |
10489
+--------------+---------------------+--------------------------------------------------------------------+
10590

106-
Controller names are camelized, this means that characters (-) and (_) are removed and the next character
107-
is uppercased. For instance, some_controller is converted to SomeController.
91+
控制器名称采用驼峰书写规则,这意味着,字符 (-) 和 (_)将被移除,同时把下一个字符转化为大写字符。比如,some_controller被转化为SomeController。
10892

10993
Since you can add many routes as you need using add(), the order in which you add the routes indicates
11094
their relevance, last routes added have more relevance than first added. Internally, all defined routes

0 commit comments

Comments
 (0)