Symfony Documentation
    Âûïóñê 2.0

    Fabien Potencier

    28 September 2011

    Îãëàâëåíèå

    I

    Êðàòêèé òóð

    3

    1

    Îáùàÿ êàðòèíà
    1.1 Çàãðóçêà Symfony2 . . .
    1.2 Ïðîâåðêà êîíôèãóðàöèè
    1.3 Ïîíèìàíèå îñíîâ . . . .
    1.4 Ðàáîòà ñ îêðóæåíèÿìè .
    1.5 Çàêëþ÷èòåëüíîå ñëîâî .

    2

    Âèä
    2.1
    2.2
    2.3
    2.4
    2.5

    3

    Êîíòðîëëåð
    3.1 Èñïîëüçîâàíèå ôîðìàòîâ . . . . . . . . .
    3.2 Ïåðåìåùåíèÿ è ïåðåíàïðàâëåíèÿ . . . .
    3.3 Ïîëó÷åíèå èíôîðìàöèè î çàïðîñå . . .
    3.4 Ñîõðàíåíèå è ïîëó÷åíèå èíôîðìàöèè èç
    3.5 Securing Resources . . . . . . . . . . . . .
    3.6 Caching Resources . . . . . . . . . . . . .
    3.7 Çàêëþ÷èòåëüíîå ñëîâî . . . . . . . . . .

    4

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    5
    5
    6
    7
    12
    14

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    15
    15
    17
    18
    20
    20

    . . . . .
    . . . . .
    . . . . .
    ñåññèè .
    . . . . .
    . . . . .
    . . . . .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .

    21
    21
    22
    23
    23
    24
    25
    26

    Àðõèòåêòóðà
    4.1 Ñòðóêòóðà ïàïîê . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    4.2 Ñèñòåìà áàíäëîâ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    4.3 Using Vendors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    27
    27
    29
    33

    Twig, êðàòêèé îáçîð . . . .
    Äåêîðèðîâàíèå øàáëîíîâ .
    Òåãè, ôèëüòðû è ôóíêöèè .
    Ýêðàíèðîâàíèå ïåðåìåííûõ
    Çàêëþ÷èòåëüíîå ñëîâî . . .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    .
    .
    .
    .
    .

    i

    4.4
    4.5
    4.6
    II

    5

    III

    6

    ii

    Êýøèðîâàíèå è Ëîãè . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    Èíòåðôåéñ êîìàíäíîé ñòðîêè . . . . . . . . . . . . . . . . . . . . . . . . .
    Çàêëþ÷èòåëüíîå ñëîâî . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    Ðóêîâîäñòâà

    Êíèãà
    5.1 Îñíîâû Symfony2 è ïðîòîêîëà HTTP
    5.2 Symfony2 versus Flat PHP . . . . . . .
    5.3 Installing and Conguring Symfony . . .
    5.4 Ñîçäàíèå ñòðàíèö â Symfony2 . . . . .
    5.5 Controller . . . . . . . . . . . . . . . . .
    5.6 Routing . . . . . . . . . . . . . . . . . .
    5.7 Creating and using Templates . . . . . .
    5.8 Áàçû äàííûõ è Doctrine (Ìîäåëè) .
    5.9 Òåñòèðîâàíèå . . . . . . . . . . . . . .
    5.10 Âàëèäàöèÿ . . . . . . . . . . . . . . . .
    5.11 Ôîðìû . . . . . . . . . . . . . . . . . .
    5.12 Security . . . . . . . . . . . . . . . . . .
    5.13 HTTP Cache . . . . . . . . . . . . . . .
    5.14 Translations . . . . . . . . . . . . . . .
    5.15 Service Container . . . . . . . . . . . . .
    5.16 Performance . . . . . . . . . . . . . . .
    5.17 Internals . . . . . . . . . . . . . . . . .
    5.18 Ñòàáèëüíûé API äëÿ Symfony2 . . . .

    33
    34
    34
    35

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    Ðåöåïòû

    Ðåöåïòû
    6.1 How to Create and store a Symfony2 Project in git . . . . . . . . .
    6.2 Êàê ñîçäàòü ñîáñòâåííûå ñòðàíèöû îøèáîê . . . . . . . . . . . .
    6.3 How to dene Controllers as Services . . . . . . . . . . . . . . . . .
    6.4 How to force routes to always use HTTPS . . . . . . . . . . . . . .
    6.5 How to allow a / character in a route parameter . . . . . . . . . .
    6.6 How to Use Assetic for Asset Management . . . . . . . . . . . . . .
    6.7 How to Minify JavaScripts and Stylesheets with YUI Compressor .
    6.8 How to Use Assetic For Image Optimization with Twig Functions .
    6.9 How to Apply an Assetic Filter to a Specic File Extension . . . .
    6.10 How to handle File Uploads with Doctrine . . . . . . . . . . . . . .
    6.11 Doctrine Extensions: Timestampable: Sluggable, Translatable, etc.
    6.12 Registering Event Listeners and Subscribers . . . . . . . . . . . . .
    6.13 How to generate Entities from an Existing Database . . . . . . . .
    6.14 How to use Doctrine's DBAL Layer . . . . . . . . . . . . . . . . .

    39
    39
    49
    63
    68
    87
    100
    121
    143
    170
    185
    199
    226
    260
    278
    293
    312
    314
    334
    337

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    339
    339
    341
    343
    344
    346
    347
    352
    354
    359
    363
    370
    371
    373
    376

    6.15
    6.16
    6.17
    6.18
    6.19
    6.20
    6.21
    6.22
    6.23
    6.24
    6.25
    6.26
    6.27
    6.28
    6.29
    6.30
    6.31
    6.32
    6.33
    6.34
    6.35
    6.36
    6.37
    6.38
    6.39
    6.40
    6.41
    6.42
    6.43
    6.44
    6.45
    6.46
    6.47
    6.48
    6.49
    6.50
    6.51
    6.52
    6.53
    6.54
    6.55
    6.56
    6.57
    6.58
    6.59

    How to work with Multiple Entity Managers . . . . . . . . . . . . . .
    Registering Custom DQL Functions . . . . . . . . . . . . . . . . . .
    How to customize Form Rendering . . . . . . . . . . . . . . . . . . .
    How to Create a Custom Form Field Type . . . . . . . . . . . . . . .
    How to create a Custom Validation Constraint . . . . . . . . . . . .
    How to Master and Create new Environments . . . . . . . . . . . . .
    How to Set External Parameters in the Service Container . . . . . .
    How to Use a Factory to Create Services . . . . . . . . . . . . . . . .
    How to Manage Common Dependencies with Parent Services . . . .
    How to work with Scopes . . . . . . . . . . . . . . . . . . . . . . . .
    How to use PdoSessionStorage to store Sessions in the Database . . .
    Bundle Structure and Best Practices . . . . . . . . . . . . . . . . . .
    How to use Bundle Inheritance to Override parts of a Bundle . . . .
    How to expose a Semantic Conguration for a Bundle . . . . . . . .
    Êàê îòïðàâëÿòü ïèñüìà . . . . . . . . . . . . . . . . . . . . . . . .
    Êàê èñïîëüçîâàòü Gmail äëÿ îòïðàâêè ïèñåì . . . . . . . . . . . .
    How to Work with Emails During Development . . . . . . . . . . . .
    How to Spool Email . . . . . . . . . . . . . . . . . . . . . . . . . . .
    How to simulate HTTP Authentication in a Functional Test . . . . .
    How to test the Interaction of several Clients . . . . . . . . . . . . .
    How to use the Proler in a Functional Test . . . . . . . . . . . . . .
    How to test Doctrine Repositories . . . . . . . . . . . . . . . . . . .
    How to add Remember Me Login Functionality . . . . . . . . . . .
    How to implement your own Voter to blacklist IP Addresses . . . . .
    Access Control Lists (ACLs) . . . . . . . . . . . . . . . . . . . . . .
    Advanced ACL Concepts . . . . . . . . . . . . . . . . . . . . . . . .
    How to force HTTPS or HTTP for Dierent URLs . . . . . . . . . .
    How to customize your Form Login . . . . . . . . . . . . . . . . . . .
    How to secure any Service or Method in your Application . . . . . .
    How to load Security Users from the Database (the entity Provider)
    How to create a custom User Provider . . . . . . . . . . . . . . . . .
    How to create a custom Authentication Provider . . . . . . . . . . .
    How to change the Default Target Path Behavior . . . . . . . . . . .
    How to use Varnish to speedup my Website . . . . . . . . . . . . . .
    How to use PHP instead of Twig for Templates . . . . . . . . . . . .
    How to autoload Classes . . . . . . . . . . . . . . . . . . . . . . . . .
    How to locate Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    How to create Console/Command-Line Commands . . . . . . . . . .
    How to optimize your development Environment for debugging . . .
    Êàê èñïîëüçîâàòü Monolog äëÿ æóðíàëèðîâàíèÿ . . . . . . . . . .
    How to extend a Class without using Inheritance . . . . . . . . . . .
    How to customize a Method Behavior without using Inheritance . . .
    How to register a new Request Format and Mime Type . . . . . . .
    How to create a custom Data Collector . . . . . . . . . . . . . . . . .
    How to Create a SOAP Web Service in a Symfony2 Controller . . . .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    380
    381
    383
    399
    399
    401
    408
    411
    415
    426
    430
    433
    438
    439
    449
    451
    453
    455
    457
    457
    458
    459
    463
    467
    470
    474
    478
    479
    487
    492
    493
    493
    503
    504
    506
    511
    513
    517
    523
    524
    529
    531
    532
    534
    537
    iii

    6.60 Symfony2 äëÿ ïîëüçîâàòåëåé symfony 1 . . . . . . . . . . . . . . . . . . . . 541
    IV

    7

    V

    8
    VI

    9

    Ñïðàâî÷íûå äîêóìåíòû

    Reference Documents
    7.1 FrameworkBundle Conguration (framework)
    7.2 AsseticBundle Conguration Reference . . . . .
    7.3 Conguration Reference . . . . . . . . . . . . .
    7.4 Security Conguration Reference . . . . . . . .
    7.5 SwiftmailerBundle Conguration . . . . . . . .
    7.6 TwigBundle Conguration Reference . . . . . .
    7.7 Conguration Reference . . . . . . . . . . . . .
    7.8 WebProlerBundle Conguration . . . . . . . .
    7.9 Form Types Reference . . . . . . . . . . . . . .
    7.10 Twig Template Form Function Reference . . . .
    7.11 Validation Constraints Reference . . . . . . . .
    7.12 The Dependency Injection Tags . . . . . . . . .
    7.13 YAML . . . . . . . . . . . . . . . . . . . . . . .
    7.14 Requirements for running Symfony2 . . . . . .
    Bundles

    Symfony SE Bundles
    Ó÷àñòèå â ïðîåêòå

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .