Skip to content

Commit 7456e3e

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: book/controller.rst book/forms.rst cookbook/map.rst.inc
2 parents ee3dfbd + 46ed478 commit 7456e3e

18 files changed

+255
-94
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/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: 14 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::
@@ -1090,7 +1090,10 @@ a route+parameters back to a URL. The
10901090
system. Take the ``blog_show`` example route from earlier::
10911091

10921092
$params = $router->match('/blog/my-blog-post');
1093-
// array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show')
1093+
// array(
1094+
// 'slug' => 'my-blog-post',
1095+
// '_controller' => 'AcmeBlogBundle:Blog:show',
1096+
// )
10941097

10951098
$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));
10961099
// /blog/my-blog-post
@@ -1103,9 +1106,12 @@ that route. With this information, any URL can easily be generated::
11031106
{
11041107
public function showAction($slug)
11051108
{
1106-
// ...
1109+
// ...
11071110

1108-
$url = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
1111+
$url = $this->get('router')->generate(
1112+
'blog_show',
1113+
array('slug' => 'my-blog-post')
1114+
);
11091115
}
11101116
}
11111117

@@ -1119,7 +1125,10 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
11191125

11201126
.. code-block:: javascript
11211127
1122-
var url = Routing.generate('blog_show', { "slug": 'my-blog-post'});
1128+
var url = Routing.generate(
1129+
'blog_show',
1130+
{"slug": 'my-blog-post'}
1131+
);
11231132
11241133
For more information, see the documentation for that bundle.
11251134

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

book/templating.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ Including this template from any other template is simple:
532532
<h1>Recent Articles<h1>
533533

534534
{% for article in articles %}
535-
{% include 'AcmeArticleBundle:Article:articleDetails.html.twig' with {'article': article} %}
535+
{% include 'AcmeArticleBundle:Article:articleDetails.html.twig'
536+
with {'article': article}
537+
%}
536538
{% endfor %}
537539
{% endblock %}
538540

@@ -582,10 +584,14 @@ articles::
582584
{
583585
public function recentArticlesAction($max = 3)
584586
{
585-
// make a database call or other logic to get the "$max" most recent articles
587+
// make a database call or other logic
588+
// to get the "$max" most recent articles
586589
$articles = ...;
587590

588-
return $this->render('AcmeArticleBundle:Article:recentList.html.twig', array('articles' => $articles));
591+
return $this->render(
592+
'AcmeArticleBundle:Article:recentList.html.twig',
593+
array('articles' => $articles)
594+
);
589595
}
590596
}
591597

@@ -815,7 +821,11 @@ correctly:
815821

816822
.. code-block:: html+php
817823

818-
<a href="<?php echo $view['router']->generate('_welcome', array(), true) ?>">Home</a>
824+
<a href="<?php echo $view['router']->generate(
825+
'_welcome',
826+
array(),
827+
true
828+
) ?>">Home</a>
819829

820830
.. index::
821831
single: Templating; Linking to assets
@@ -1062,7 +1072,10 @@ customize the markup specifically for your application. By digging into the
10621072
// some logic to retrieve the blogs
10631073
$blogs = ...;
10641074

1065-
$this->render('AcmeBlogBundle:Blog:index.html.twig', array('blogs' => $blogs));
1075+
$this->render(
1076+
'AcmeBlogBundle:Blog:index.html.twig',
1077+
array('blogs' => $blogs)
1078+
);
10661079
}
10671080

10681081
When the ``AcmeBlogBundle:Blog:index.html.twig`` is rendered, Symfony2 actually

0 commit comments

Comments
 (0)