diff --git a/zh/index.rst b/zh/index.rst index 963ec56c208a..412099530a2f 100755 --- a/zh/index.rst +++ b/zh/index.rst @@ -29,7 +29,7 @@ Phalcon不只是性能优越,我们的目标是让它强大而且易于使用! 本文档的中文地址存放在 http://phalcon.5iunix.net -Github上的地址为: https://github.com/netstu/phalcondocs ,您如果发现有些地方译的有些操蛋,烦请你clone它,并完善她。 +Github上的地址为: https://github.com/netstu/phalcondocs ,您如果发现有些地方译的有些操蛋,烦请你fork它,并完善她。 目录 ------------- diff --git a/zh/reference/applications.rst b/zh/reference/applications.rst index 2f5bfa0e78e4..8404b0ed7709 100644 --- a/zh/reference/applications.rst +++ b/zh/reference/applications.rst @@ -1,18 +1,14 @@ MVC Applications ================ -All the hard work behind orchestrating the operation of MVC in Phalcon is normally done by -:doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>`. This component encapsulates all the complex -operations required in the background, instantiating every component needed and integrating it with the -project, to allow the MVC pattern to operate as desired. +在 Phalcon 中,所有复杂的MVC相关工作都是由 :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` 来完成的。该组件封装了所有复杂的后台操作,包括每一个组件的实例化,组件之间的集成等。 Single or Multi Module Applications ----------------------------------- -With this component you can run various types of MVC structures: +使用此组件,您可以运行不同类型的MVC结构: Single Module ^^^^^^^^^^^^^ -Single MVC applications consist of one module only. Namespaces can be used but are not necessary. -An application like this would have the following file structure: +单MVC应用程序只包含一个module,可以使用命名空间,但不是必需的。这样的应用程序的文件结构如下: .. code-block:: php @@ -26,7 +22,7 @@ An application like this would have the following file structure: img/ js/ -If namespaces are not used, the following bootstrap file could be used to orchestrate the MVC flow: +如果不使用命名空间,引导文件被用来协调MVC流程: .. code-block:: php @@ -58,7 +54,7 @@ If namespaces are not used, the following bootstrap file could be used to orches echo $e->getMessage(); } -If namespaces are used, the following bootstrap can be used: +如果使用命名空间,引导文件可以这样做: .. code-block:: php @@ -103,7 +99,7 @@ If namespaces are used, the following bootstrap can be used: Multi Module ^^^^^^^^^^^^ -A multi-module application uses the same document root for more than one module. In this case the following file structure can be used: +一个multi-module(多模块)的应用程序是指使用相同的Document Root,但有超过一个module。在这种情况下,程序的文件结构如下: .. code-block:: php @@ -124,7 +120,7 @@ A multi-module application uses the same document root for more than one module. img/ js/ -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: +在 apps/ 目录下的每个目录都有自己的MVC结构,Module.php是每个Module特定的设置: .. code-block:: php @@ -178,7 +174,7 @@ Each directory in apps/ have its own MVC structure. A Module.php is present to c } -A special bootstrap file is required to load the a multi-module MVC architecture: +一个特殊的引导文件,用以载入 multi-module MVC 结构: .. code-block:: php @@ -250,8 +246,7 @@ A special bootstrap file is required to load the a multi-module MVC architecture echo $e->getMessage(); } -If you want to maintain the module configuration in the bootstrap file you can use an anonymous function to register the -module: +如果你想把配置文件完全写入到引导文件,你可以使用一个匿名函数的方式来注册 Module : .. code-block:: php @@ -278,16 +273,11 @@ module: ) ); -When :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` have modules registered, always is -necessary that every matched route returns a valid module. Each registered module has an associated class -that offers functions to set the module itself up. Each module class definition must implement two -methods: registerAutoloaders() and registerServices(), they will be called by -:doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` according to the module to be executed. +当 :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。 -Understanding the default behavior +了解默认行为 ---------------------------------- -If you've been following the :doc:`tutorial ` or have generated the code using :doc:`Phalcon Devtools `, -you may recognize the following bootstrap file: +如果你一直关注 :doc:`tutorial ` 或 使用 :doc:`Phalcon Devtools ` 生成过代码,你可能会熟悉以下的引导文件: .. code-block:: php @@ -310,7 +300,7 @@ you may recognize the following bootstrap file: echo "PhalconException: ", $e->getMessage(); } -The core of all the work of the controller occurs when handle() is invoked: +所有控制器工作的核心是 handle()方法被调用: .. code-block:: php @@ -318,7 +308,7 @@ The core of all the work of the controller occurs when handle() is invoked: echo $application->handle()->getContent(); -If you do not wish to use :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>`, the code above can be changed as follows: +如果您不希望使用 :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` ,上面的代码可以修改如下: .. code-block:: php @@ -364,14 +354,11 @@ If you do not wish to use :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Ap // Print the response echo $response->getContent(); -Although the above is a lot more verbose than the code needed while using :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>`, -it offers an alternative in boostraping your application. Depending on your needs, you might want to have full control of what -should be instantiated or not, or replace certain components with those of your own to extend the default functionality. +尽管上面的代码显得比使用 :doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` 罗唆,但它提供了一种替代bootstrap文件的方式。根据你的需要,你可能希望完全掌握哪些类应该被实例化,或使用自己的组件来扩展默认的功能。 Application Events ------------------ -:doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` is able to send events to the :doc:`EventsManager ` -(if it is present). Events are triggered using the type "application". The following events are supported: +:doc:`Phalcon\\Mvc\\Application <../api/Phalcon_Mvc_Application>` 能够将事件发送到 :doc:`EventsManager `,事件管理器通过触发 "application"来实现,支持以下的事件: +---------------------+--------------------------------------------------------------+ | Event Name | Triggered | @@ -385,7 +372,7 @@ Application Events | afterHandleRequest | After execute the dispatch loop | +---------------------+--------------------------------------------------------------+ -The following example demonstrates how to attach listeners to this component: +下面的示例演示如何在此组件上添加监听器: .. code-block:: php @@ -402,7 +389,7 @@ The following example demonstrates how to attach listeners to this component: } ); -External Resources +相关资源 ------------------ * `MVC examples on Github `_ diff --git a/zh/reference/routing.rst b/zh/reference/routing.rst index ed5204cda21c..a28e18605dce 100755 --- a/zh/reference/routing.rst +++ b/zh/reference/routing.rst @@ -1,13 +1,10 @@ -Routing -======= -The router component allows defining routes that are mapped to controllers or handlers that should receive -the request. A router simply parses a URI to determine this information. The router has two modes: MVC -mode and match-only mode. The first mode is ideal for working with MVC applications. +路由器(Routing) +============================= +router组件允许定义用户请求对应到哪个控制器或Action。router解析 URI 以确定这些信息。路由器有两种模式:MVC模式和匹配模式(match-only)。第一种模式是使用MVC应用程序的理想选择。 Defining Routes --------------- -:doc:`Phalcon\\Mvc\\Router <../api/Phalcon_Mvc_Router>` provides advanced routing capabilities. In MVC mode, -you can define routes and map them to controllers/actions that you require. A route is defined as follows: +:doc:`Phalcon\\Mvc\\Router <../api/Phalcon_Mvc_Router>` 提供了一套先进的路由功能。在MVC模式中,你可以自定义路由规则,对应到你需要的 controllers/actions 上。路由的定义如下: .. code-block:: php @@ -36,14 +33,9 @@ you can define routes and map them to controllers/actions that you require. A ro $router->handle(); -The method add() receives as first parameter a pattern and optionally a set of paths as second parameter. -In this case if the URI is exactly: /admin/users/my-profile, then the "users" controller with its action "profile" -will be executed. Currently, the router does not execute the controller and action, it only collects this -information to inform the correct component (ie. :doc:`Phalcon\\Mvc\\Dispatcher <../api/Phalcon_Mvc_Dispatcher>`) -that this is controller/action it should to execute. +add() 方法接收两个参数,第一个参数是一个匹配字符串,第二个参数为一组可选的路径。在这种情况下,URI /admin/users/my-profile, "users"代表控制器,"profile"代表Ation。目前,该路由器不并不执行控制器和Action,只为组件(如: :doc:`Phalcon\\Mvc\\Dispatcher <../api/Phalcon_Mvc_Dispatcher>`) 收集信息,然后由分发器决定是否立即执行。 -An application can have many paths, define routes one by one can be a cumbersome task. In these cases we can -create more flexible routes: +应用程序可能有很多个不同的路径,如果一个一个的定义路由的话,会非常麻烦。在这种情况下,我们可以使用更灵活的方式创建route: .. code-block:: php @@ -62,8 +54,7 @@ create more flexible routes: ) ); -In the example above, using wildcards we make a route valid for many URIs. For example, by accessing the -following URL (/admin/users/a/delete/dave/301) then: +在上面的例子中,我们使用通配符来匹配路由。例如,通过访问URL (/admin/users/a/delete/dave/301) ,解析为: +------------+---------------+ | Controller | users | @@ -75,17 +66,11 @@ following URL (/admin/users/a/delete/dave/301) then: | Parameter | 301 | +------------+---------------+ -The method add() receives a pattern that optionally could have predefined placeholders and regular expression -modifiers. All the routing patterns must start with a slash character (/). The regular expression syntax used -is the same as the `PCRE regular expressions`_. Note that, it is not necessary to add regular expression -delimiters. All routes patterns are case-insensitive. +add()方法接收一个模式,可选择使用预定义占位符和正则表达式修饰符。所有的路由模式必须以斜线字符(/)开始。正则表达式语法使用与 `PCRE regular expressions`_ 相同的语法。需要注意的是,不必要添加正则表达式分隔符。所有的路由模式是不区分大小写的。 -The second parameter defines how the matched parts should bind to the controller/action/parameters. Matching -parts are placeholders or subpatterns delimited by parentheses (round brackets). In the above example, the -first subpattern matched (:controller) is the controller part of the route, the second the action and so on. +第二个参数定义了如何将匹配部分绑定到controller/action/parameters。匹配部分是占位符或团圆括号中的子模式。另外,在上述的例子中,第一个子模式匹配(:controller),是route中控制器部分,第二个是action,等。 -These placeholders help writing regular expressions that are more readable for developers and easier -to understand. The following placeholders are supported: +这些占位符使用正则表达式,更易读,更容易为开发人员理解。支持以下占位符: +--------------+---------------------+--------------------------------------------------------------------+ | Placeholder | Regular Expression | Usage | @@ -103,8 +88,7 @@ to understand. The following placeholders are supported: | /:int | /([0-9]+) | Matches an integer parameter | +--------------+---------------------+--------------------------------------------------------------------+ -Controller names are camelized, this means that characters (-) and (_) are removed and the next character -is uppercased. For instance, some_controller is converted to SomeController. +控制器名称采用驼峰书写规则,这意味着,字符 (-) 和 (_)将被移除,同时把下一个字符转化为大写字符。比如,some_controller被转化为SomeController。 Since you can add many routes as you need using add(), the order in which you add the routes indicates their relevance, last routes added have more relevance than first added. Internally, all defined routes diff --git a/zh/reference/tags.rst b/zh/reference/tags.rst index ba5af9541ffc..c8a07e3411ce 100755 --- a/zh/reference/tags.rst +++ b/zh/reference/tags.rst @@ -1,13 +1,15 @@ -View Helpers -============ -Writing and maintaining HTML markup can quickly become a tedious task because of the naming conventions and numerous attributes that have to be taken into consideration. Phalcon deals with this complexity by offering :doc:`Phalcon\\Tag <../api/Phalcon_Tag>`, which in turn offers view helpers to generate HTML markup. +视图助手(View Helpers) +=================================== +编写和维护HTML标记是一项繁琐的任务,因为有许多命名约定及属性需要考虑。Phalcon提供了 :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 来处理这种复杂性,然后 Phalcon 会把视图助手编写的代码又生成HTML标记,用于正常显示HTML。 + +此组件同时可用于 HTML+ PHP 的模板文件中,也可以用于 :doc:`Volt ` 模板引擎: .. highlights:: - This guide is not intended to be a complete documentation of available helpers and their arguments. Please visit the :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` page in the API for a complete reference. + 本指南不是一个完整的文档,只讲述了视图助手及其参数使用的其中一部分。完整的API参考,请访问::doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 。 -Using Name Aliasing +使用别名 ------------------- -You could use name aliasing to get short names for classes. In this case, a Tag name can be used to alias the :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` class. +你可以对类进行别名定义以获取更短的名称,在这种情况下,Tag可以代替 :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 。 .. code-block:: php @@ -15,10 +17,10 @@ You could use name aliasing to get short names for classes. In this case, a Tag Document Type of Content ------------------------ -Phalcon provides Phalcon\\Tag::setDoctype() helper to set document type of the content. Document type setting may affect HTML output produced by other tag helpers. -For example, if you set XHTML document type family, helpers that return or output HTML tags will produce self-closing tags to follow valid XHTML standard. +Phalcon中,使用 Phalcon\\Tag::setDoctype() 助手可以设置HTML文档类型,文档类型的定义可能会影响其他 HTML 标签的输出。 +例如,如果你设置为XHTML的文档类型,所有标签必须闭合,也就是说开始标签要有相应的结束标签。 -Available document type constants in Phalcon\\Tag namespace are: +Phalcon\\Tag 命名空间定义了以下一些文档类型常量: +----------------------+------------------------+ | Constant | Document type | @@ -46,13 +48,13 @@ Available document type constants in Phalcon\\Tag namespace are: | XHTML5 | XHTML 5 | +----------------------+------------------------+ -Setting document type. +设置文档类型. .. code-block:: php -Getting document type. +获取文档类型. .. code-block:: html+php @@ -61,7 +63,7 @@ Getting document type. -The following HTML will be produced. +下面是编译后的HTML代码: .. code-block:: html @@ -73,8 +75,8 @@ The following HTML will be produced. Generating Links ---------------- -A real common task in any web application or website is to produce links that allow us to navigate from one page to another. -When they are internal URLs we can create them in the following manner: +在任何Web应用程序或网站中,连接是非常重要的,它能使我们从一个页面跳转到另一个页面。 +我们可以通过以下方式创建内部连接: .. code-block:: html+php @@ -84,11 +86,11 @@ When they are internal URLs we can create them in the following manner: 'show-product', 'id' => 123, 'name' => 'carrots')) ?> -Actually, all produced URLs are generated by the component :doc:`Phalcon\\Mvc\\Url ` (or service "url" failing) +其实,文档中所有的URLs都是通过组件 :doc:`Phalcon\\Mvc\\Url ` (or service "url" failing) 生成的。 -Creating Forms +创建表单 -------------- -Forms in web applications play an essential part in retrieving user input. The following example shows how to implement a simple search form using view helpers: +在Web应用程序中,从表单中获取用户输入是一个应用程序或网站的重要组成部分。下面的示例演示如何使用视图助手创建一个简单的搜索表单: .. code-block:: html+php @@ -108,7 +110,7 @@ Forms in web applications play an essential part in retrieving user input. The f -This last code will generate the following HTML: +上面的助手代码将生成下面的HTML代码: .. code-block:: html+php @@ -118,9 +120,9 @@ This last code will generate the following HTML: -Helpers to Generate Form Elements +创建表单元素 --------------------------------- -Phalcon provides a series of helpers to generate form elements such as text fields, buttons and more. The first parameter of each helper is always the name of the element to be generated. When the form is submitted, the name will be passed along with the form data. In a controller you can get these values using the same name by using the getPost() and getQuery() methods on the request object ($this->request). +Phalcon 提供了一系列的助手用于生成表单元素,比如:文本框,按钮等。助手的第一个参数是要生成的表单的名称,当提交表单时,这个名字被当做数据传递。在控制器中,你可以使用 request对象($this->request)的 getPost()和 getQuery()方法,用这个名字得到用户提交的数据。 .. code-block:: html+php @@ -143,10 +145,9 @@ Phalcon provides a series of helpers to generate form elements such as text fiel "value"=> "5" )) ?> -Making Select Boxes +生成选择菜单 ------------------- -Generating select boxes (select box) is easy, especially if the related data is stored in PHP associative arrays. The helpers for select elements are Phalcon\\Tag::select() and Phalcon\\Tag::selectStatic(). -Phalcon\\Tag::selectStatic() has been was specifically designed to work with :doc:`Phalcon\\Mvc\\Model `, while Phalcon\\Tag::selectStatic() can with PHP arrays. +生成选择框是容易的,特别是相关的数据已经存储到PHP数组中时。生成选择框可以使用 Phalcon\\Tag::select() 和 Phalcon\\Tag::selectStatic(). Phalcon\\Tag::select() 是专门设计与 :doc:`Phalcon\\Mvc\\Model ` 一起使用,而 Phalcon\\Tag::selectStatic() 则是与PHP数组一起使用。 .. code-block:: php @@ -172,7 +173,7 @@ Phalcon\\Tag::selectStatic() has been was specifically designed to work with :do ) ); -The following HTML will generated: +下面是生成的HTML代码: .. code-block:: html @@ -187,7 +188,7 @@ The following HTML will generated: -You can add an "empty" option to the generated HTML: +有时,为了显示的需要,你想要添加一个空值的option项: .. code-block:: php @@ -239,7 +240,7 @@ You can add an "empty" option to the generated HTML: Assigning HTML attributes ------------------------- -All the helpers accept an array as their first parameter which can contain additional HTML attributes for the element generated. +所有的助手都接收一个数组,数组的第一个参数作为名称,其他的用于生成额外的HTML属性。 .. code-block:: html+php @@ -252,7 +253,7 @@ All the helpers accept an array as their first parameter which can contain addit ) ) ?> -The following HTML will generated: +会产生下面的HTML代码: .. code-block:: html @@ -264,10 +265,7 @@ Setting Helper Values From Controllers ^^^^^^^^^^^^^^^^ -It is a good programming principle for MVC frameworks to set specific values for form elements in the view. -You can set those values directly from the controller using Phalcon\\Tag::setDefaultValue(). -This helper preloads a value for any helpers present in the view. If any helper in the view has -a name that matches the preloaded value, it will use it, unless a value is directly assigned on the helper in the view. +在视图中对表单元素设置特定值是一个良好的用户体验,你可以在控制器中通过 Phalcon\\Tag::setDefaultValue() 设置默认值。 .. code-block:: php @@ -283,7 +281,7 @@ a name that matches the preloaded value, it will use it, unless a value is direc } -At the view, a selectStatic helper matches the same index used to preset the value. In this case "color": +在视图文件中,使用 selectStatic 助手提供一些预设值,名称为 "color": .. code-block:: php @@ -300,7 +298,7 @@ At the view, a selectStatic helper matches the same index used to preset the val ) ); -This will generate the following select tag with the value "Blue" selected: +下面是生成的HTML代码,同时值为 "Blue" 的option选项被默认选中: .. code-block:: html @@ -312,8 +310,7 @@ This will generate the following select tag with the value "Blue" selected: From the Request ^^^^^^^^^^^^^^^^ -A special feature that the :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` helpers have is that they keep the values -of form helpers between requests. This way you can easily show validation messages without losing entered data. +:doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 助手的一个重要的功能是,它能在请求时保持提交的数据。这样,你就可以轻松的显示验证信息,而不会丢失输入的数据。 Specifying values directly ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -322,8 +319,7 @@ When this parameter is present, any preset value using setDefaultValue() or via Changing dynamically the Document Title --------------------------------------- -:doc:`Phalcon\\Tag <../api/Phalcon_Tag>` offers helpers to change dynamically the document title from the controller. -The following example demonstrates just that: +:doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 助手还提供了可以在控制器中动态修改标题的功能。下面的例子演示了这一点: .. code-block:: php @@ -355,7 +351,7 @@ The following example demonstrates just that: -The following HTML will generated: +下面是生成的HTML代码: .. code-block:: html+php @@ -370,7 +366,7 @@ The following HTML will generated: Static Content Helpers ---------------------- -:doc:`Phalcon\\Tag <../api/Phalcon_Tag>` also provide helpers to generate tags such as script, link or img. They aid in quick and easy generation of the static resources of your application +:doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 助手还提供了生成 script,link, img 这些标签的功能。它能帮助你在你的应用程序中快速的生成静态资源文件。 Images ^^^^^^ @@ -416,9 +412,9 @@ Javascript // Generate echo \Phalcon\Tag::javascriptInclude("javascript/jquery.min.js"); -Creating your own helpers +创建自定义助手 ------------------------- -You can easily create your own helpers by extending the :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` and implementing your own helper. Below is a simple example of a custom helper: +你可以通过继承 :doc:`Phalcon\\Tag <../api/Phalcon_Tag>` 创建你自己的自定义助手,下面是一个简单的例子: .. code-block:: php @@ -478,5 +474,4 @@ You can easily create your own helpers by extending the :doc:`Phalcon\\Tag <../a } -In next chapter, we'll talk about :doc:`Volt ` a faster template engine for PHP, where you can use a -more friendly syntax for using helpers provided by Phalcon\Tag. \ No newline at end of file +在下一章中,我们将讨论 :doc:`Volt ` ,一个更快的PHP模板引擎,在那里你可以使用由 Phalcon\Tag 提供的一种更友好的语法来使用助手工具。 \ No newline at end of file