Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
Conflicts:
	book/controller.rst
	book/forms.rst
	cookbook/map.rst.inc
  • Loading branch information
weaverryan committed Dec 1, 2012
2 parents ee3dfbd + 46ed478 commit 7456e3e
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 94 deletions.
31 changes: 23 additions & 8 deletions book/controller.rst
Expand Up @@ -472,10 +472,13 @@ value to each variable.
object::

$httpKernel = $this->container->get('http_kernel');
$response = $httpKernel->forward('AcmeHelloBundle:Hello:fancy', array(
'name' => $name,
'color' => 'green',
));
$response = $httpKernel->forward(
'AcmeHelloBundle:Hello:fancy',
array(
'name' => $name,
'color' => 'green',
)
);

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

$content = $this->renderView('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
$content = $this->renderView(
'AcmeHelloBundle:Hello:index.html.twig',
array('name' => $name)
);

return new Response($content);

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

return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
return $this->render(
'AcmeHelloBundle:Hello:index.html.twig',
array('name' => $name)
);

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

$templating = $this->get('templating');
$content = $templating->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
$content = $templating->render(
'AcmeHelloBundle:Hello:index.html.twig',
array('name' => $name)
);

.. note::

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

$templating->render('AcmeHelloBundle:Hello/Greetings:index.html.twig', array('name' => $name));
$templating->render(
'AcmeHelloBundle:Hello/Greetings:index.html.twig',
array('name' => $name)
);
// index.html.twig found in Resources/views/Hello/Greetings is rendered.

.. index::
Expand Down
11 changes: 8 additions & 3 deletions book/doctrine.rst
Expand Up @@ -472,7 +472,9 @@ on its ``id`` value::
->find($id);

if (!$product) {
throw $this->createNotFoundException('No product found for id '.$id);
throw $this->createNotFoundException(
'No product found for id '.$id
);
}

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

if (!$product) {
throw $this->createNotFoundException('No product found for id '.$id);
throw $this->createNotFoundException(
'No product found for id '.$id
);
}

$product->setName('New product name!');
Expand Down Expand Up @@ -1308,7 +1312,8 @@ and ``nullable``. Take a few examples:
/**
* A string field with length 255 that cannot be null
* (reflecting the default values for the "type", "length" and *nullable* options)
* (reflecting the default values for the "type", "length"
* and *nullable* options)
*
* @ORM\Column()
*/
Expand Down
4 changes: 3 additions & 1 deletion book/forms.rst
Expand Up @@ -1565,7 +1565,9 @@ method to specify the option::
{
$collectionConstraint = new Collection(array(
'name' => new Length(array("min" => 5)),
'email' => new Email(array('message' => 'Invalid email address')),
'email' => new Email(
array('message' => 'Invalid email address')
),
));

$resolver->setDefaults(array(
Expand Down
20 changes: 16 additions & 4 deletions book/from_flat_php_to_symfony2.rst
Expand Up @@ -554,7 +554,10 @@ them for you. Here's the same sample application, now built in Symfony2::
->createQuery('SELECT p FROM AcmeBlogBundle:Post p')
->execute();

return $this->render('AcmeBlogBundle:Blog:list.html.php', array('posts' => $posts));
return $this->render(
'AcmeBlogBundle:Blog:list.html.php',
array('posts' => $posts)
);
}

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

return $this->render('AcmeBlogBundle:Blog:show.html.php', array('post' => $post));
return $this->render(
'AcmeBlogBundle:Blog:show.html.php',
array('post' => $post)
);
}
}

Expand All @@ -590,7 +596,10 @@ now quite a bit simpler:
<ul>
<?php foreach ($posts as $post): ?>
<li>
<a href="<?php echo $view['router']->generate('blog_show', array('id' => $post->getId())) ?>">
<a href="<?php echo $view['router']->generate(
'blog_show',
array('id' => $post->getId())
) ?>">
<?php echo $post->getTitle() ?>
</a>
</li>
Expand All @@ -605,7 +614,10 @@ The layout is nearly identical:
<!DOCTYPE html>
<html>
<head>
<title><?php echo $view['slots']->output('title', 'Default title') ?></title>
<title><?php echo $view['slots']->output(
'title',
'Default title'
) ?></title>
</head>
<body>
<?php echo $view['slots']->output('_content') ?>
Expand Down
14 changes: 11 additions & 3 deletions book/page_creation.rst
Expand Up @@ -288,10 +288,16 @@ of writing the HTML inside the controller, render a template instead:
{
public function indexAction($name)
{
return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
return $this->render(
'AcmeHelloBundle:Hello:index.html.twig',
array('name' => $name)
);
// render a PHP template instead
// return $this->render('AcmeHelloBundle:Hello:index.html.php', array('name' => $name));
// return $this->render(
// 'AcmeHelloBundle:Hello:index.html.php',
// array('name' => $name)
// );
}
}
Expand Down Expand Up @@ -903,7 +909,9 @@ file of your choice::
// app/AppKernel.php
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
$loader->load(
__DIR__.'/config/config_'.$this->getEnvironment().'.yml'
);
}

You already know that the ``.yml`` extension can be changed to ``.xml`` or
Expand Down
8 changes: 6 additions & 2 deletions book/propel.rst
Expand Up @@ -181,7 +181,9 @@ value::
->findPk($id);

if (!$product) {
throw $this->createNotFoundException('No product found for id '.$id);
throw $this->createNotFoundException(
'No product found for id '.$id
);
}

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

if (!$product) {
throw $this->createNotFoundException('No product found for id '.$id);
throw $this->createNotFoundException(
'No product found for id '.$id
);
}

$product->setName('New product name!');
Expand Down
19 changes: 14 additions & 5 deletions book/routing.rst
Expand Up @@ -417,7 +417,7 @@ match, giving the ``page`` parameter a value of ``2``. Perfect.

.. tip::

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

.. index::
Expand Down Expand Up @@ -1090,7 +1090,10 @@ a route+parameters back to a URL. The
system. Take the ``blog_show`` example route from earlier::

$params = $router->match('/blog/my-blog-post');
// array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show')
// array(
// 'slug' => 'my-blog-post',
// '_controller' => 'AcmeBlogBundle:Blog:show',
// )

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

$url = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
$url = $this->get('router')->generate(
'blog_show',
array('slug' => 'my-blog-post')
);
}
}

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

.. code-block:: javascript
var url = Routing.generate('blog_show', { "slug": 'my-blog-post'});
var url = Routing.generate(
'blog_show',
{"slug": 'my-blog-post'}
);
For more information, see the documentation for that bundle.

Expand Down
17 changes: 11 additions & 6 deletions book/security.rst
Expand Up @@ -434,17 +434,22 @@ Next, create the controller that will display the login form::

// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}

return $this->render('AcmeSecurityBundle:Security:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
return $this->render(
'AcmeSecurityBundle:Security:login.html.twig',
array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
)
);
}
}

Expand Down
26 changes: 21 additions & 5 deletions book/service_container.rst
Expand Up @@ -565,10 +565,14 @@ something like this::
Without using the service container, you can create a new ``NewsletterManager``
fairly easily from inside a controller::

use Acme\HelloBundle\Newsletter\NewsletterManager;

// ...

public function sendNewsletterAction()
{
$mailer = $this->get('my_mailer');
$newsletter = new Acme\HelloBundle\Newsletter\NewsletterManager($mailer);
$newsletter = new NewsletterManager($mailer);
// ...
}

Expand Down Expand Up @@ -618,7 +622,10 @@ the service container gives you a much more appealing option:
use Symfony\Component\DependencyInjection\Reference;
// ...
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
$container->setParameter(
'newsletter_manager.class',
'Acme\HelloBundle\Newsletter\NewsletterManager'
);
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
Expand Down Expand Up @@ -708,7 +715,10 @@ Injecting the dependency by the setter method just needs a change of syntax:
use Symfony\Component\DependencyInjection\Reference;
// ...
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
$container->setParameter(
'newsletter_manager.class',
'Acme\HelloBundle\Newsletter\NewsletterManager'
);
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
Expand Down Expand Up @@ -767,12 +777,18 @@ it exists and do nothing if it doesn't:
use Symfony\Component\DependencyInjection\ContainerInterface;
// ...
$container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
$container->setParameter(
'newsletter_manager.class',
'Acme\HelloBundle\Newsletter\NewsletterManager'
);
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
'%newsletter_manager.class%',
array(new Reference('my_mailer', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
array(new Reference(
'my_mailer',
ContainerInterface::IGNORE_ON_INVALID_REFERENCE
))
));
In YAML, the special ``@?`` syntax tells the service container that the dependency
Expand Down
23 changes: 18 additions & 5 deletions book/templating.rst
Expand Up @@ -532,7 +532,9 @@ Including this template from any other template is simple:
<h1>Recent Articles<h1>

{% for article in articles %}
{% include 'AcmeArticleBundle:Article:articleDetails.html.twig' with {'article': article} %}
{% include 'AcmeArticleBundle:Article:articleDetails.html.twig'
with {'article': article}
%}
{% endfor %}
{% endblock %}

Expand Down Expand Up @@ -582,10 +584,14 @@ articles::
{
public function recentArticlesAction($max = 3)
{
// make a database call or other logic to get the "$max" most recent articles
// make a database call or other logic
// to get the "$max" most recent articles
$articles = ...;

return $this->render('AcmeArticleBundle:Article:recentList.html.twig', array('articles' => $articles));
return $this->render(
'AcmeArticleBundle:Article:recentList.html.twig',
array('articles' => $articles)
);
}
}

Expand Down Expand Up @@ -815,7 +821,11 @@ correctly:

.. code-block:: html+php

<a href="<?php echo $view['router']->generate('_welcome', array(), true) ?>">Home</a>
<a href="<?php echo $view['router']->generate(
'_welcome',
array(),
true
) ?>">Home</a>

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

$this->render('AcmeBlogBundle:Blog:index.html.twig', array('blogs' => $blogs));
$this->render(
'AcmeBlogBundle:Blog:index.html.twig',
array('blogs' => $blogs)
);
}

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

0 comments on commit 7456e3e

Please sign in to comment.