Skip to content

Commit f1f0345

Browse files
Reducing code sample line lengths to avoid horizontal scrolling
1 parent c8e1d56 commit f1f0345

13 files changed

+216
-88
lines changed

book/controller.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,12 @@ 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', array(
477+
'name' => $name,
478+
'color' => 'green',
479+
)
480+
);
479481

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

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

495500
return new Response($content);
496501

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

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

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

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

522533
.. note::
523534

524535
It is possible to render templates in deeper subdirectories as well, however
525536
be careful to avoid the pitfall of making your directory structure unduly
526537
elaborate::
527538

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

531545
.. index::
@@ -642,7 +656,10 @@ For example, imagine you're processing a form submit::
642656
if ($form->isValid()) {
643657
// do some sort of processing
644658

645-
$this->get('session')->setFlash('notice', 'Your changes were saved!');
659+
$this->get('session')->setFlash(
660+
'notice',
661+
'Your changes were saved!'
662+
);
646663

647664
return $this->redirect($this->generateUrl(...));
648665
}

book/doctrine.rst

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

472472
if (!$product) {
473-
throw $this->createNotFoundException('No product found for id '.$id);
473+
throw $this->createNotFoundException(
474+
'No product found for id '.$id
475+
);
474476
}
475477

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

557559
if (!$product) {
558-
throw $this->createNotFoundException('No product found for id '.$id);
560+
throw $this->createNotFoundException(
561+
'No product found for id '.$id
562+
);
559563
}
560564

561565
$product->setName('New product name!');
@@ -1306,7 +1310,8 @@ and ``nullable``. Take a few examples:
13061310
13071311
/**
13081312
* A string field with length 255 that cannot be null
1309-
* (reflecting the default values for the "type", "length" and *nullable* options)
1313+
* (reflecting the default values for the "type", "length"
1314+
* and *nullable* options)
13101315
*
13111316
* @ORM\Column()
13121317
*/

book/forms.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,9 @@ method to specify the option::
14771477
{
14781478
$collectionConstraint = new Collection(array(
14791479
'name' => new MinLength(5),
1480-
'email' => new Email(array('message' => 'Invalid email address')),
1480+
'email' => new Email(
1481+
array('message' => 'Invalid email address')
1482+
),
14811483
));
14821484

14831485
return array('validation_constraint' => $collectionConstraint);

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
@@ -290,10 +290,16 @@ of writing the HTML inside the controller, render a template instead:
290290
{
291291
public function indexAction($name)
292292
{
293-
return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
293+
return $this->render(
294+
'AcmeHelloBundle:Hello:index.html.twig',
295+
array('name' => $name)
296+
);
294297
295298
// render a PHP template instead
296-
// return $this->render('AcmeHelloBundle:Hello:index.html.php', array('name' => $name));
299+
// return $this->render(
300+
// 'AcmeHelloBundle:Hello:index.html.php',
301+
// array('name' => $name)
302+
// );
297303
}
298304
}
299305
@@ -902,7 +908,9 @@ file of your choice::
902908
// app/AppKernel.php
903909
public function registerContainerConfiguration(LoaderInterface $loader)
904910
{
905-
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
911+
$loader->load(
912+
__DIR__.'/config/config_'.$this->getEnvironment().'.yml'
913+
);
906914
}
907915

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

book/propel.rst

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ persist it to the database and fetch it back out.
1818
.. sidebar:: Code along with the example
1919

2020
If you want to follow along with the example in this chapter, create an
21-
``AcmeStoreBundle`` via:
22-
21+
``AcmeStoreBundle`` via:
22+
2323
.. code-block:: bash
2424
2525
$ php app/console generate:bundle --namespace=Acme/StoreBundle
@@ -171,19 +171,21 @@ Fetching Objects from the Database
171171
Fetching an object back from the database is even easier. For example, suppose
172172
you've configured a route to display a specific ``Product`` based on its ``id``
173173
value::
174-
174+
175175
// ...
176176
use Acme\StoreBundle\Model\ProductQuery;
177-
177+
178178
public function showAction($id)
179179
{
180180
$product = ProductQuery::create()
181181
->findPk($id);
182-
182+
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
}
186-
188+
187189
// ... do something, like pass the $product object into a template
188190
}
189191

@@ -192,22 +194,24 @@ Updating an Object
192194

193195
Once you've fetched an object from Propel, updating it is easy. Suppose you
194196
have a route that maps a product id to an update action in a controller::
195-
197+
196198
// ...
197199
use Acme\StoreBundle\Model\ProductQuery;
198-
200+
199201
public function updateAction($id)
200202
{
201203
$product = ProductQuery::create()
202204
->findPk($id);
203-
205+
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
}
207-
211+
208212
$product->setName('New product name!');
209213
$product->save();
210-
214+
211215
return $this->redirect($this->generateUrl('homepage'));
212216
}
213217

@@ -227,12 +231,12 @@ method on the object::
227231

228232
Querying for Objects
229233
--------------------
230-
234+
231235
Propel provides generated ``Query`` classes to run both basic and complex queries
232236
without any work::
233-
237+
234238
\Acme\StoreBundle\Model\ProductQuery::create()->findPk($id);
235-
239+
236240
\Acme\StoreBundle\Model\ProductQuery::create()
237241
->filterByName('Foo')
238242
->findOne();
@@ -287,13 +291,13 @@ Start by adding the ``category`` definition in your ``schema.xml``:
287291
<column name="name" type="varchar" primaryString="true" size="100" />
288292
<column name="price" type="decimal" />
289293
<column name="description" type="longvarchar" />
290-
294+
291295
<column name="category_id" type="integer" />
292296
<foreign-key foreignTable="category">
293297
<reference local="category_id" foreign="id" />
294298
</foreign-key>
295299
</table>
296-
300+
297301
<table name="category">
298302
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
299303
<column name="name" type="varchar" primaryString="true" size="100" />
@@ -326,23 +330,23 @@ Now, let's see the code in action. Imagine you're inside a controller::
326330
use Acme\StoreBundle\Model\Category;
327331
use Acme\StoreBundle\Model\Product;
328332
use Symfony\Component\HttpFoundation\Response;
329-
333+
330334
class DefaultController extends Controller
331335
{
332336
public function createProductAction()
333337
{
334338
$category = new Category();
335339
$category->setName('Main Products');
336-
340+
337341
$product = new Product();
338342
$product->setName('Foo');
339343
$product->setPrice(19.99);
340344
// relate this product to the category
341345
$product->setCategory($category);
342-
346+
343347
// save the whole
344348
$product->save();
345-
349+
346350
return new Response(
347351
'Created product id: '.$product->getId().' and category id: '.$category->getId()
348352
);
@@ -363,15 +367,15 @@ before. First, fetch a ``$product`` object and then access its related
363367

364368
// ...
365369
use Acme\StoreBundle\Model\ProductQuery;
366-
370+
367371
public function showAction($id)
368372
{
369373
$product = ProductQuery::create()
370374
->joinWithCategory()
371375
->findPk($id);
372-
376+
373377
$categoryName = $product->getCategory()->getName();
374-
378+
375379
// ...
376380
}
377381

@@ -395,7 +399,7 @@ inserted, updated, deleted, etc).
395399
To add a hook, just add a new method to the object class::
396400

397401
// src/Acme/StoreBundle/Model/Product.php
398-
402+
399403
// ...
400404
class Product extends BaseProduct
401405
{

0 commit comments

Comments
 (0)