Skip to content

Commit efdbe7d

Browse files
committed
🌍 Translate Framework/Web
1 parent 03aa387 commit efdbe7d

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

docs/framework/web.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Controllers for Web Applications
1+
# Web应用程序的控制器
22

3-
Symlex controllers are plain PHP classes by default. They are configured as public services either in `app/config/web.yml` (HTML) or `app/config/rest.yml` (REST):
3+
默认情况下, Symlex 控制器是普通的 PHP 类。 它们在 `app/config/web.yml`HTML)或 `app/config/rest.yml`REST)中配置为公共服务:
44

55
```yaml
66
controller.web.index:
77
public: true
88
class: App\Controller\Web\IndexController
9-
9+
1010
controller.rest.v1.users:
1111
public: true
1212
class: App\Controller\Rest\V1\UsersController
@@ -16,36 +16,34 @@ controller.rest.v1.users:
1616
```
1717
1818
!!! note
19-
In many other frameworks, controllers aren't services by default. Some developers are used to give
20-
controllers direct access to the service container instead of using dependency injection, which makes testing more
21-
difficult and leads to less portable code (framework lock-in).
19+
在许多其他框架中,默认情况下控制器不是服务。 一些开发人员习惯于让控制器直接访问服务容器,而不是使用依赖注入,这使得测试更加困难并导致更少的可移植代码(框架锁定)。
20+
21+
路由器将请求实例作为最后一个参数传递给每个匹配的控制器操作。 它包含请求参数和标题,如上所述 [Symfony 的文档](http://symfony.com/doc/current/book/http_fundamentals.html#requests-and-responses-in-symfony).
2222
23-
The routers pass on the request instance to each matched controller action as last argument. It contains request parameters and headers as described on the [Symfony documentation](http://symfony.com/doc/current/book/http_fundamentals.html#requests-and-responses-in-symfony).
23+
**Web 控制器操作** 可以返回不同的
2424
25-
**Web controller actions** can either return
25+
- **null**: 将呈现匹配的 Twig 模板
26+
- 一个 **array**: Twig 模板可以将这些值作为变量访问
27+
- 一个 **string**: 用户将被重定向到 URL
28+
- 或者 `Symfony\Component\HttpFoundation\Response` 的对象
2629

27-
- **null**: Matching Twig template will be rendered
28-
- an **array**: Twig template can access those values as variables
29-
- a **string**: User will be redirected to URL
30-
- or a `Symfony\Component\HttpFoundation\Response` object
31-
32-
Twig's template base directory can be configured in `app/config/twig.yml` (`twig.path`). The template filename is matching the request route: `[twig.path]/[controller]/[action].twig`.
30+
Twig 的模板基目录可以在`app/config/twig.yml`(`twig.path`)中配置。 模板文件名与请求路径匹配:`[twig.path]/[controller]/[action].twig`。
3331

34-
If no controller or action name is given, `index` is the default e.g. `index/index.twig` will be used for rending `/`.
32+
如果没有给出控制器或动作名称,`index` 是默认值,例如 `index/index.twig`将用于渲染 `/`
3533

3634
!!! example
3735
```php
3836
<?php
39-
37+
4038
namespace App\Controller\Web;
41-
39+
4240
class IndexController
4341
{
4442
/**
45-
* Renders the template in app/templates/default/index.twig
43+
* app/templates/default/index.twig 中呈现模板
4644
*/
4745
public function indexAction()
4846
{
4947
}
5048
}
51-
```
49+
```

0 commit comments

Comments
 (0)