Skip to content

Commit dccf123

Browse files
committed
Merge branch '2.1'
2 parents 30d49c7 + a03f06f commit dccf123

33 files changed

+376
-143
lines changed

book/controller.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,13 @@ value to each variable.
472472
object::
473473

474474
$httpKernel = $this->container->get('http_kernel');
475-
$response = $httpKernel->forward('AcmeHelloBundle:Hello:fancy', array(
476-
'name' => $name,
477-
'color' => 'green',
478-
));
475+
$response = $httpKernel->forward(
476+
'AcmeHelloBundle:Hello:fancy',
477+
array(
478+
'name' => $name,
479+
'color' => 'green',
480+
)
481+
);
479482

480483
.. index::
481484
single: Controller; Rendering templates
@@ -490,14 +493,20 @@ that's responsible for generating the HTML (or other format) for the controller.
490493
The ``renderView()`` method renders a template and returns its content. The
491494
content from the template can be used to create a ``Response`` object::
492495

493-
$content = $this->renderView('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
496+
$content = $this->renderView(
497+
'AcmeHelloBundle:Hello:index.html.twig',
498+
array('name' => $name)
499+
);
494500

495501
return new Response($content);
496502

497503
This can even be done in just one step with the ``render()`` method, which
498504
returns a ``Response`` object containing the content from the template::
499505

500-
return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
506+
return $this->render(
507+
'AcmeHelloBundle:Hello:index.html.twig',
508+
array('name' => $name)
509+
);
501510

502511
In both cases, the ``Resources/views/Hello/index.html.twig`` template inside
503512
the ``AcmeHelloBundle`` will be rendered.
@@ -517,15 +526,21 @@ The Symfony templating engine is explained in great detail in the
517526
service. The ``templating`` service can also be used directly::
518527

519528
$templating = $this->get('templating');
520-
$content = $templating->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
529+
$content = $templating->render(
530+
'AcmeHelloBundle:Hello:index.html.twig',
531+
array('name' => $name)
532+
);
521533

522534
.. note::
523535

524536
It is possible to render templates in deeper subdirectories as well, however
525537
be careful to avoid the pitfall of making your directory structure unduly
526538
elaborate::
527539

528-
$templating->render('AcmeHelloBundle:Hello/Greetings:index.html.twig', array('name' => $name));
540+
$templating->render(
541+
'AcmeHelloBundle:Hello/Greetings:index.html.twig',
542+
array('name' => $name)
543+
);
529544
// index.html.twig found in Resources/views/Hello/Greetings is rendered.
530545

531546
.. index::

book/doctrine.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ on its ``id`` value::
472472
->find($id);
473473

474474
if (!$product) {
475-
throw $this->createNotFoundException('No product found for id '.$id);
475+
throw $this->createNotFoundException(
476+
'No product found for id '.$id
477+
);
476478
}
477479

478480
// ... do something, like pass the $product object into a template
@@ -557,7 +559,9 @@ you have a route that maps a product id to an update action in a controller::
557559
$product = $em->getRepository('AcmeStoreBundle:Product')->find($id);
558560

559561
if (!$product) {
560-
throw $this->createNotFoundException('No product found for id '.$id);
562+
throw $this->createNotFoundException(
563+
'No product found for id '.$id
564+
);
561565
}
562566

563567
$product->setName('New product name!');
@@ -1308,7 +1312,8 @@ and ``nullable``. Take a few examples:
13081312
13091313
/**
13101314
* A string field with length 255 that cannot be null
1311-
* (reflecting the default values for the "type", "length" and *nullable* options)
1315+
* (reflecting the default values for the "type", "length"
1316+
* and *nullable* options)
13121317
*
13131318
* @ORM\Column()
13141319
*/

book/forms.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,9 @@ method to specify the option::
15651565
{
15661566
$collectionConstraint = new Collection(array(
15671567
'name' => new Length(array("min" => 5)),
1568-
'email' => new Email(array('message' => 'Invalid email address')),
1568+
'email' => new Email(
1569+
array('message' => 'Invalid email address')
1570+
),
15691571
));
15701572

15711573
$resolver->setDefaults(array(

book/from_flat_php_to_symfony2.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ them for you. Here's the same sample application, now built in Symfony2::
554554
->createQuery('SELECT p FROM AcmeBlogBundle:Post p')
555555
->execute();
556556

557-
return $this->render('AcmeBlogBundle:Blog:list.html.php', array('posts' => $posts));
557+
return $this->render(
558+
'AcmeBlogBundle:Blog:list.html.php',
559+
array('posts' => $posts)
560+
);
558561
}
559562

560563
public function showAction($id)
@@ -570,7 +573,10 @@ them for you. Here's the same sample application, now built in Symfony2::
570573
throw $this->createNotFoundException();
571574
}
572575

573-
return $this->render('AcmeBlogBundle:Blog:show.html.php', array('post' => $post));
576+
return $this->render(
577+
'AcmeBlogBundle:Blog:show.html.php',
578+
array('post' => $post)
579+
);
574580
}
575581
}
576582

@@ -590,7 +596,10 @@ now quite a bit simpler:
590596
<ul>
591597
<?php foreach ($posts as $post): ?>
592598
<li>
593-
<a href="<?php echo $view['router']->generate('blog_show', array('id' => $post->getId())) ?>">
599+
<a href="<?php echo $view['router']->generate(
600+
'blog_show',
601+
array('id' => $post->getId())
602+
) ?>">
594603
<?php echo $post->getTitle() ?>
595604
</a>
596605
</li>
@@ -605,7 +614,10 @@ The layout is nearly identical:
605614
<!DOCTYPE html>
606615
<html>
607616
<head>
608-
<title><?php echo $view['slots']->output('title', 'Default title') ?></title>
617+
<title><?php echo $view['slots']->output(
618+
'title',
619+
'Default title'
620+
) ?></title>
609621
</head>
610622
<body>
611623
<?php echo $view['slots']->output('_content') ?>

book/page_creation.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,16 @@ of writing the HTML inside the controller, render a template instead:
288288
{
289289
public function indexAction($name)
290290
{
291-
return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
291+
return $this->render(
292+
'AcmeHelloBundle:Hello:index.html.twig',
293+
array('name' => $name)
294+
);
292295
293296
// render a PHP template instead
294-
// return $this->render('AcmeHelloBundle:Hello:index.html.php', array('name' => $name));
297+
// return $this->render(
298+
// 'AcmeHelloBundle:Hello:index.html.php',
299+
// array('name' => $name)
300+
// );
295301
}
296302
}
297303
@@ -903,7 +909,9 @@ file of your choice::
903909
// app/AppKernel.php
904910
public function registerContainerConfiguration(LoaderInterface $loader)
905911
{
906-
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
912+
$loader->load(
913+
__DIR__.'/config/config_'.$this->getEnvironment().'.yml'
914+
);
907915
}
908916

909917
You already know that the ``.yml`` extension can be changed to ``.xml`` or

book/performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ finally finds the file it's looking for.
5656

5757
The simplest solution is to tell Composer to build a "class map" (i.e. a
5858
big array of the locations of all the classes). This can be done from the
59-
command line, and might become part of your deploy process::
59+
command line, and might become part of your deploy process:
6060

6161
.. code-block:: bash
6262

book/propel.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ value::
181181
->findPk($id);
182182

183183
if (!$product) {
184-
throw $this->createNotFoundException('No product found for id '.$id);
184+
throw $this->createNotFoundException(
185+
'No product found for id '.$id
186+
);
185187
}
186188

187189
// ... do something, like pass the $product object into a template
@@ -202,7 +204,9 @@ have a route that maps a product id to an update action in a controller::
202204
->findPk($id);
203205

204206
if (!$product) {
205-
throw $this->createNotFoundException('No product found for id '.$id);
207+
throw $this->createNotFoundException(
208+
'No product found for id '.$id
209+
);
206210
}
207211

208212
$product->setName('New product name!');

book/routing.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ match, giving the ``page`` parameter a value of ``2``. Perfect.
417417

418418
.. tip::
419419

420-
Routes with optional parameters at the end will not match on requests
420+
Routes with optional parameters at the end will not match on requests
421421
with a trailing slash (i.e. ``/blog/`` will not match, ``/blog`` will match).
422422

423423
.. index::
@@ -787,6 +787,12 @@ a slash. URLs matching this route might look like:
787787
each value of ``_format``. The ``_format`` parameter is a very powerful way
788788
to render the same content in different formats.
789789

790+
.. note::
791+
792+
Sometimes you want to make certain parts of your routes globally configurable.
793+
Symfony2.1 provides you with a way to do this by leveraging service container
794+
parameters. Read more about this in ":doc:`/cookbook/routing/service_container_parameters`.
795+
790796
Special Routing Parameters
791797
~~~~~~~~~~~~~~~~~~~~~~~~~~
792798

@@ -1103,7 +1109,10 @@ a route+parameters back to a URL. The
11031109
system. Take the ``blog_show`` example route from earlier::
11041110

11051111
$params = $router->match('/blog/my-blog-post');
1106-
// array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show')
1112+
// array(
1113+
// 'slug' => 'my-blog-post',
1114+
// '_controller' => 'AcmeBlogBundle:Blog:show',
1115+
// )
11071116

11081117
$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));
11091118
// /blog/my-blog-post
@@ -1116,9 +1125,12 @@ that route. With this information, any URL can easily be generated::
11161125
{
11171126
public function showAction($slug)
11181127
{
1119-
// ...
1128+
// ...
11201129

1121-
$url = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
1130+
$url = $this->get('router')->generate(
1131+
'blog_show',
1132+
array('slug' => 'my-blog-post')
1133+
);
11221134
}
11231135
}
11241136

@@ -1132,7 +1144,10 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
11321144

11331145
.. code-block:: javascript
11341146
1135-
var url = Routing.generate('blog_show', { "slug": 'my-blog-post'});
1147+
var url = Routing.generate(
1148+
'blog_show',
1149+
{"slug": 'my-blog-post'}
1150+
);
11361151
11371152
For more information, see the documentation for that bundle.
11381153

book/security.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,22 @@ Next, create the controller that will display the login form::
434434

435435
// get the login error if there is one
436436
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
437-
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
437+
$error = $request->attributes->get(
438+
SecurityContext::AUTHENTICATION_ERROR
439+
);
438440
} else {
439441
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
440442
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
441443
}
442444

443-
return $this->render('AcmeSecurityBundle:Security:login.html.twig', array(
444-
// last username entered by the user
445-
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
446-
'error' => $error,
447-
));
445+
return $this->render(
446+
'AcmeSecurityBundle:Security:login.html.twig',
447+
array(
448+
// last username entered by the user
449+
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
450+
'error' => $error,
451+
)
452+
);
448453
}
449454
}
450455

book/service_container.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,14 @@ something like this::
565565
Without using the service container, you can create a new ``NewsletterManager``
566566
fairly easily from inside a controller::
567567

568+
use Acme\HelloBundle\Newsletter\NewsletterManager;
569+
570+
// ...
571+
568572
public function sendNewsletterAction()
569573
{
570574
$mailer = $this->get('my_mailer');
571-
$newsletter = new Acme\HelloBundle\Newsletter\NewsletterManager($mailer);
575+
$newsletter = new NewsletterManager($mailer);
572576
// ...
573577
}
574578

@@ -618,7 +622,10 @@ the service container gives you a much more appealing option:
618622
use Symfony\Component\DependencyInjection\Reference;
619623
620624
// ...
621-
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
625+
$container->setParameter(
626+
'newsletter_manager.class',
627+
'Acme\HelloBundle\Newsletter\NewsletterManager'
628+
);
622629
623630
$container->setDefinition('my_mailer', ...);
624631
$container->setDefinition('newsletter_manager', new Definition(
@@ -708,7 +715,10 @@ Injecting the dependency by the setter method just needs a change of syntax:
708715
use Symfony\Component\DependencyInjection\Reference;
709716
710717
// ...
711-
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
718+
$container->setParameter(
719+
'newsletter_manager.class',
720+
'Acme\HelloBundle\Newsletter\NewsletterManager'
721+
);
712722
713723
$container->setDefinition('my_mailer', ...);
714724
$container->setDefinition('newsletter_manager', new Definition(
@@ -767,12 +777,18 @@ it exists and do nothing if it doesn't:
767777
use Symfony\Component\DependencyInjection\ContainerInterface;
768778
769779
// ...
770-
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
780+
$container->setParameter(
781+
'newsletter_manager.class',
782+
'Acme\HelloBundle\Newsletter\NewsletterManager'
783+
);
771784
772785
$container->setDefinition('my_mailer', ...);
773786
$container->setDefinition('newsletter_manager', new Definition(
774787
'%newsletter_manager.class%',
775-
array(new Reference('my_mailer', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
788+
array(new Reference(
789+
'my_mailer',
790+
ContainerInterface::IGNORE_ON_INVALID_REFERENCE
791+
))
776792
));
777793
778794
In YAML, the special ``@?`` syntax tells the service container that the dependency

0 commit comments

Comments
 (0)