Permalink
Browse files

Merge branch '2.1'

  • Loading branch information...
2 parents 30d49c7 + a03f06f commit dccf1238fa829a019700ddb69a33eba30f80b59b @weaverryan weaverryan committed Dec 6, 2012
View
@@ -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
@@ -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.
@@ -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::
View
@@ -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
@@ -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!');
@@ -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()
*/
View
@@ -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(
@@ -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)
@@ -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)
+ );
}
}
@@ -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>
@@ -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') ?>
View
@@ -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)
+ // );
}
}
@@ -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
View
@@ -56,7 +56,7 @@ finally finds the file it's looking for.
The simplest solution is to tell Composer to build a "class map" (i.e. a
big array of the locations of all the classes). This can be done from the
-command line, and might become part of your deploy process::
+command line, and might become part of your deploy process:
.. code-block:: bash
View
@@ -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
@@ -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!');
View
@@ -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::
@@ -787,6 +787,12 @@ a slash. URLs matching this route might look like:
each value of ``_format``. The ``_format`` parameter is a very powerful way
to render the same content in different formats.
+.. note::
+
+ Sometimes you want to make certain parts of your routes globally configurable.
+ Symfony2.1 provides you with a way to do this by leveraging service container
+ parameters. Read more about this in ":doc:`/cookbook/routing/service_container_parameters`.
+
Special Routing Parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1103,7 +1109,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
@@ -1116,9 +1125,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')
+ );
}
}
@@ -1132,7 +1144,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.
View
@@ -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,
+ )
+ );
}
}
View
@@ -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);
// ...
}
@@ -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(
@@ -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(
@@ -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
Oops, something went wrong.

0 comments on commit dccf123

Please sign in to comment.