@@ -368,157 +368,6 @@ It's that easy! To review:
368
368
369
369
* The HTTP headers and content of the ``Response `` object are sent back to the client.
370
370
371
- A Symfony Request in Action
372
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
373
-
374
- Without diving into too much detail, here is this process in action. Suppose
375
- you want to add a ``/contact `` page to your Symfony application. First, start
376
- by adding an entry for ``/contact `` to your routing configuration file:
377
-
378
- .. configuration-block ::
379
-
380
- .. code-block :: yaml
381
-
382
- # app/config/routing.yml
383
- contact :
384
- path : /contact
385
- defaults : { _controller: AppBundle:Main:contact }
386
-
387
- .. code-block :: xml
388
-
389
- <!-- app/config/routing.xml -->
390
- <?xml version =" 1.0" encoding =" UTF-8" ?>
391
- <routes xmlns =" http://symfony.com/schema/routing"
392
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
393
- xsi : schemaLocation =" http://symfony.com/schema/routing
394
- http://symfony.com/schema/routing/routing-1.0.xsd" >
395
-
396
- <route id =" contact" path =" /contact" >
397
- <default key =" _controller" >AppBundle:Main:contact</default >
398
- </route >
399
- </routes >
400
-
401
- .. code-block :: php
402
-
403
- // app/config/routing.php
404
- use Symfony\Component\Routing\Route;
405
- use Symfony\Component\Routing\RouteCollection;
406
-
407
- $collection = new RouteCollection();
408
- $collection->add('contact', new Route('/contact', array(
409
- '_controller' => 'AppBundle:Main:contact',
410
- )));
411
-
412
- return $collection;
413
-
414
- When someone visits the ``/contact `` page, this route is matched, and the
415
- specified controller is executed. As you'll learn in the
416
- :ref: `routing chapter <controller-string-syntax >`, the ``AppBundle:Main:contact ``
417
- string is a short syntax that points to a specific controller - ``contactAction() `` -
418
- inside a controller class called - ``MainController ``::
419
-
420
- // src/AppBundle/Controller/MainController.php
421
- namespace AppBundle\Controller;
422
-
423
- use Symfony\Component\HttpFoundation\Response;
424
-
425
- class MainController
426
- {
427
- public function contactAction()
428
- {
429
- return new Response('<h1>Contact us!</h1>');
430
- }
431
- }
432
-
433
- In this example, the controller creates a
434
- :class: `Symfony\\ Component\\ HttpFoundation\\ Response ` object with the HTML
435
- ``<h1>Contact us!</h1> ``. In the :doc: `Controller chapter </book/controller >`,
436
- you'll learn how a controller can render templates, allowing your "presentation"
437
- code (i.e. anything that actually writes out HTML) to live in a separate
438
- template file. This frees up the controller to worry only about the hard
439
- stuff: interacting with the database, handling submitted data, or sending
440
- email messages.
441
-
442
- .. _symfony2-build-your-app-not-your-tools :
443
-
444
- Symfony: Build your App, not your Tools
445
- ---------------------------------------
446
-
447
- You now know that the goal of any app is to interpret each incoming request
448
- and create an appropriate response. As an application grows, it becomes more
449
- difficult to keep your code organized and maintainable. Invariably, the same
450
- complex tasks keep coming up over and over again: persisting things to the
451
- database, rendering and reusing templates, handling form submissions, sending
452
- emails, validating user input and handling security.
453
-
454
- The good news is that none of these problems is unique. Symfony provides
455
- a framework full of tools that allow you to build your application, not your
456
- tools. With Symfony, nothing is imposed on you: you're free to use the full
457
- Symfony Framework, or just one piece of Symfony all by itself.
458
-
459
- .. index ::
460
- single: Symfony Components
461
-
462
- .. _standalone-tools-the-symfony2-components :
463
-
464
- Standalone Tools: The Symfony *Components *
465
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
466
-
467
- So what *is * Symfony? First, Symfony is a collection of over twenty independent
468
- libraries that can be used inside *any * PHP project. These libraries, called
469
- the *Symfony Components *, contain something useful for almost any situation,
470
- regardless of how your project is developed. To name a few:
471
-
472
- :doc: `HttpFoundation </components/http_foundation/introduction >`
473
- Contains the ``Request `` and ``Response `` classes, as well as other classes for
474
- handling sessions and file uploads.
475
-
476
- :doc: `Routing </components/routing/introduction >`
477
- Powerful and fast routing system that allows you to map a specific URI
478
- (e.g. ``/contact ``) to information about how that request should be handled (e.g.
479
- that the ``contactAction() `` controller method should be executed).
480
-
481
- :doc: `Form </components/form/introduction >`
482
- A full-featured and flexible framework for creating forms and handling form
483
- submissions.
484
-
485
- `Validator `_
486
- A system for creating rules about data and then validating whether or not
487
- user-submitted data follows those rules.
488
-
489
- :doc: `Templating </components/templating/introduction >`
490
- A toolkit for rendering templates, handling template inheritance (i.e. a
491
- template is decorated with a layout) and performing other common template tasks.
492
-
493
- :doc: `Security </components/security/introduction >`
494
- A powerful library for handling all types of security inside an application.
495
-
496
- :doc: `Translation </components/translation/introduction >`
497
- A framework for translating strings in your application.
498
-
499
- Each one of these components is decoupled and can be used in *any * PHP project,
500
- regardless of whether or not you use the Symfony Framework. Every part is
501
- made to be used if needed and replaced when necessary.
502
-
503
- .. _the-full-solution-the-symfony2-framework :
504
-
505
- The Full Solution: The Symfony *Framework *
506
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507
-
508
- So then, what *is * the Symfony *Framework *? The *Symfony Framework * is
509
- a PHP library that accomplishes two distinct tasks:
510
-
511
- #. Provides a selection of components (i.e. the Symfony Components) and
512
- third-party libraries (e.g. `Swift Mailer `_ for sending emails);
513
-
514
- #. Provides sensible configuration and a "glue" library that ties all of these
515
- pieces together.
516
-
517
- The goal of the framework is to integrate many independent tools in order
518
- to provide a consistent experience for the developer. Even the framework
519
- itself is a Symfony bundle (i.e. a plugin) that can be configured or replaced
520
- entirely.
521
-
522
371
Symfony provides a powerful set of tools for rapidly developing web applications
523
372
without imposing on your application. Normal users can quickly start development
524
373
by using a Symfony distribution, which provides a project skeleton with
0 commit comments