diff --git a/book/controller.rst b/book/controller.rst index ba82c671f09..0fefce9f679 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -94,8 +94,8 @@ a controller object. Controllers are also called *actions*. :linenos: // src/Acme/HelloBundle/Controller/HelloController.php - namespace Acme\HelloBundle\Controller; + use Symfony\Component\HttpFoundation\Response; class HelloController @@ -208,8 +208,8 @@ passed to that method: 'green' )); - // further modify the response or return it directly + // ... further modify the response or return it directly return $response; } @@ -570,7 +570,8 @@ If you're extending the base controller class, do the following:: public function indexAction() { - $product = // retrieve the object from database + // retrieve the object from database + $product = ...; if (!$product) { throw $this->createNotFoundException('The product does not exist'); } diff --git a/book/doctrine.rst b/book/doctrine.rst index 451a19cdcc7..93779c7c937 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -48,7 +48,7 @@ information. By convention, this information is usually configured in an .. code-block:: ini - ;app/config/parameters.ini + ; app/config/parameters.ini [parameters] database_driver = pdo_mysql database_host = localhost @@ -64,6 +64,7 @@ information. By convention, this information is usually configured in an .. code-block:: yaml + # app/config/config.yml doctrine: dbal: driver: %database_driver% @@ -366,9 +367,10 @@ of the bundle: :linenos: // src/Acme/StoreBundle/Controller/DefaultController.php + + // ... use Acme\StoreBundle\Entity\Product; use Symfony\Component\HttpFoundation\Response; - // ... public function createAction() { @@ -444,7 +446,7 @@ on its ``id`` value:: throw $this->createNotFoundException('No product found for id '.$id); } - // do something, like pass the $product object into a template + // ... do something, like pass the $product object into a template } When you query for a particular type of object, you always use what's known @@ -605,7 +607,7 @@ for just one object, you can use the ``getSingleResult()`` method instead:: returned (if you're querying on something that could feasibly return more than one result):: - $query = $em->createQuery('SELECT ....') + $query = $em->createQuery('SELECT ...') ->setMaxResults(1); try { @@ -710,6 +712,7 @@ To do this, add the name of the repository class to your mapping definition. .. code-block:: xml + @@ -792,6 +795,7 @@ To relate the ``Category`` and ``Product`` entities, start by creating a .. code-block:: php-annotations // src/Acme/StoreBundle/Entity/Category.php + // ... use Doctrine\Common\Collections\ArrayCollection; @@ -852,6 +856,7 @@ object, you'll want to add a ``$category`` property to the ``Product`` class: .. code-block:: php-annotations // src/Acme/StoreBundle/Entity/Product.php + // ... class Product @@ -928,10 +933,10 @@ Saving Related Entities Now, let's see the code in action. Imagine you're inside a controller:: // ... + use Acme\StoreBundle\Entity\Category; use Acme\StoreBundle\Entity\Product; use Symfony\Component\HttpFoundation\Response; - // ... class DefaultController extends Controller { @@ -1058,7 +1063,6 @@ can avoid the second query by issuing a join in the original query. Add the following method to the ``ProductRepository`` class:: // src/Acme/StoreBundle/Repository/ProductRepository.php - public function findOneByIdJoinedToCategory($id) { $query = $this->getEntityManager() @@ -1162,6 +1166,7 @@ the current date, only when the entity is first persisted (i.e. inserted): .. code-block:: xml + diff --git a/book/forms.rst b/book/forms.rst index 5d669574dad..68f2fa39be7 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -147,7 +147,6 @@ helper functions: .. code-block:: html+jinja {# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #} -
{{ form_widget(form) }} @@ -157,7 +156,6 @@ helper functions: .. code-block:: html+php - enctype($form) ?> > widget($form) ?> @@ -386,8 +384,7 @@ you'll need to specify which validation group(s) your form should use:: $form = $this->createFormBuilder($users, array( 'validation_groups' => array('registration'), - ))->add(...) - ; + ))->add(...); If you're creating :ref:`form classes` (a good practice), then you'll need to add the following to the ``getDefaultOptions()`` @@ -558,7 +555,6 @@ of code. Of course, you'll usually need much more flexibility when rendering: .. code-block:: html+jinja {# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #} - {{ form_errors(form) }} @@ -572,8 +568,7 @@ of code. Of course, you'll usually need much more flexibility when rendering: .. code-block:: html+php - - + enctype($form) ?>> errors($form) ?> @@ -754,7 +749,6 @@ that will house the logic for building the task form: .. code-block:: php // src/Acme/TaskBundle/Form/Type/TaskType.php - namespace Acme\TaskBundle\Form\Type; use Symfony\Component\Form\AbstractType; @@ -787,7 +781,7 @@ form "type"). It can be used to quickly build a form object in the controller: public function newAction() { - $task = // ... + $task = ...; $form = $this->createForm(new TaskType(), $task); // ... @@ -1052,7 +1046,6 @@ do this, create a new template file that will store the new markup: .. code-block:: html+jinja {# src/Acme/TaskBundle/Resources/views/Form/fields.html.twig #} - {% block field_row %} {% spaceless %}
@@ -1066,7 +1059,6 @@ do this, create a new template file that will store the new markup: .. code-block:: html+php -
label($form, $label) ?> errors($form) ?> @@ -1083,7 +1075,6 @@ renders the form: .. code-block:: html+jinja {# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #} - {% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' %} {% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' 'AcmeTaskBundle:Form:fields2.html.twig' %} @@ -1093,7 +1084,6 @@ renders the form: .. code-block:: html+php - setTheme($form, array('AcmeTaskBundle:Form')) ?> setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?> @@ -1219,7 +1209,6 @@ file: .. code-block:: yaml # app/config/config.yml - twig: form: resources: @@ -1229,7 +1218,6 @@ file: .. code-block:: xml - AcmeTaskBundle:Form:fields.html.twig @@ -1240,7 +1228,6 @@ file: .. code-block:: php // app/config/config.php - $container->loadFromExtension('twig', array( 'form' => array('resources' => array( 'AcmeTaskBundle:Form:fields.html.twig', @@ -1297,7 +1284,6 @@ file: .. code-block:: yaml # app/config/config.yml - framework: templating: form: @@ -1309,7 +1295,6 @@ file: .. code-block:: xml - @@ -1322,7 +1307,6 @@ file: .. code-block:: php // app/config/config.php - $container->loadFromExtension('framework', array( 'templating' => array('form' => array('resources' => array( diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index 289f4aacd63..2d5c47f04d3 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -27,13 +27,13 @@ persisted to the database. Writing in flat PHP is quick and dirty: + List of Posts @@ -54,6 +54,7 @@ persisted to the database. Writing in flat PHP is quick and dirty: That's quick to write, fast to execute, and, as your app grows, impossible to maintain. There are several problems that need to be addressed: @@ -85,7 +86,6 @@ the code that prepares the HTML "presentation": List of Posts @@ -146,7 +147,6 @@ of the application are isolated in a new file called ``model.php``: + <?php echo $view['slots']->output('title', 'Default title') ?> @@ -699,7 +700,6 @@ for example, the list template written in Twig: .. code-block:: html+jinja {# src/Acme/BlogBundle/Resources/views/Blog/list.html.twig #} - {% extends "::layout.html.twig" %} {% block title %}List of Posts{% endblock %} @@ -708,7 +708,7 @@ for example, the list template written in Twig:
    {% for post in posts %}
  • - + {{ post.title }}
  • @@ -721,7 +721,7 @@ The corresponding ``layout.html.twig`` template is also easier to write: .. code-block:: html+jinja {# app/Resources/views/layout.html.twig #} - + {% block title %}Default title{% endblock %} diff --git a/book/http_cache.rst b/book/http_cache.rst index a7e795022b4..5094fbeac07 100644 --- a/book/http_cache.rst +++ b/book/http_cache.rst @@ -144,7 +144,6 @@ To enable caching, modify the code of a front controller to use the caching kernel:: // web/app.php - require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; require_once __DIR__.'/../app/AppCache.php'; @@ -173,7 +172,6 @@ finely tuned via a set of options you can set by overriding the ``getOptions()`` method:: // app/AppCache.php - use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache; class AppCache extends HttpCache @@ -643,7 +641,7 @@ exposing a simple and efficient pattern:: // the ETag or the Last-Modified value // (based on the Request, data is retrieved from // a database or a key-value store for instance) - $article = // ... + $article = ...; // create a Response with a ETag and/or a Last-Modified header $response = new Response(); @@ -656,7 +654,7 @@ exposing a simple and efficient pattern:: return $response; } else { // do more work here - like retrieving more data - $comments = // ... + $comments = ...; // or render a template with the $response you've already started return $this->render( @@ -776,14 +774,15 @@ as this is the only useful one outside of Akamaï context: .. code-block:: html + - Some content + ... some content - More content + ... more content @@ -1052,4 +1051,4 @@ Learn more from the Cookbook .. _`HTTP Bis`: http://tools.ietf.org/wg/httpbis/ .. _`P4 - Conditional Requests`: http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12 .. _`P6 - Caching: Browser and intermediary caches`: http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-12 -.. _`ESI`: http://www.w3.org/TR/esi-lang \ No newline at end of file +.. _`ESI`: http://www.w3.org/TR/esi-lang diff --git a/book/http_fundamentals.rst b/book/http_fundamentals.rst index a2b441f7a0d..57a9acbcbf1 100644 --- a/book/http_fundamentals.rst +++ b/book/http_fundamentals.rst @@ -1,4 +1,4 @@ -.. index:: +. . index:: single: Symfony2 Fundamentals Symfony2 and HTTP Fundamentals @@ -128,7 +128,7 @@ like this: Content-Type: text/html - + The HTTP response contains the requested resource (the HTML content in this @@ -368,7 +368,6 @@ on that value. This can get ugly quickly: .. code-block:: php // index.php - $request = Request::createFromGlobals(); $path = $request->getPathInfo(); // the URI path being requested diff --git a/book/internals.rst b/book/internals.rst index abab980fe57..860763868e6 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -323,7 +323,7 @@ The purpose of this event is to allow other systems to modify or replace the public function onKernelResponse(FilterResponseEvent $event) { $response = $event->getResponse(); - // .. modify the response object + // ... modify the response object } The ``FrameworkBundle`` registers several listeners: diff --git a/book/propel.rst b/book/propel.rst index 739403b87bf..76f33b92a51 100644 --- a/book/propel.rst +++ b/book/propel.rst @@ -140,9 +140,10 @@ is pretty easy. Add the following method to the ``DefaultController`` of the bundle:: // src/Acme/StoreBundle/Controller/DefaultController.php + + // ... use Acme\StoreBundle\Model\Product; use Symfony\Component\HttpFoundation\Response; - // ... public function createAction() { @@ -172,6 +173,7 @@ Fetching an object back from the database is even easier. For example, suppose you've configured a route to display a specific ``Product`` based on its ``id`` value:: + // ... use Acme\StoreBundle\Model\ProductQuery; public function showAction($id) @@ -183,7 +185,7 @@ value:: throw $this->createNotFoundException('No product found for id '.$id); } - // do something, like pass the $product object into a template + // ... do something, like pass the $product object into a template } Updating an Object @@ -192,6 +194,7 @@ Updating an Object Once you've fetched an object from Propel, updating it is easy. Suppose you have a route that maps a product id to an update action in a controller:: + // ... use Acme\StoreBundle\Model\ProductQuery; public function updateAction($id) @@ -252,7 +255,6 @@ If you want to reuse some queries, you can add your own methods to the ``ProductQuery`` class:: // src/Acme/StoreBundle/Model/ProductQuery.php - class ProductQuery extends BaseProductQuery { public function filterByExpensivePrice() @@ -326,7 +328,6 @@ Now, let's see the code in action. Imagine you're inside a controller:: use Acme\StoreBundle\Model\Category; use Acme\StoreBundle\Model\Product; use Symfony\Component\HttpFoundation\Response; - // ... class DefaultController extends Controller { diff --git a/book/routing.rst b/book/routing.rst index b09986a663a..dc88c95d343 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -80,15 +80,16 @@ pattern that points to a specific PHP class and method: .. code-block:: php // src/Acme/BlogBundle/Controller/BlogController.php - namespace Acme\BlogBundle\Controller; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; class BlogController extends Controller { public function showAction($slug) { - $blog = // use the $slug variable to query the database + // use the $slug variable to query the database + $blog = ...; return $this->render('AcmeBlogBundle:Blog:show.html.twig', array( 'blog' => $blog, @@ -1145,7 +1146,7 @@ a template helper function: .. code-block:: html+jinja - + Read this blog post. @@ -1161,7 +1162,7 @@ Absolute URLs can also be generated. .. code-block:: html+jinja - + Read this blog post. diff --git a/book/security.rst b/book/security.rst index e58fcc05612..5a8f9d5e1c4 100644 --- a/book/security.rst +++ b/book/security.rst @@ -814,8 +814,8 @@ authorization from inside a controller: .. code-block:: php - use Symfony\Component\Security\Core\Exception\AccessDeniedException; // ... + use Symfony\Component\Security\Core\Exception\AccessDeniedException; public function helloAction($name) { @@ -833,6 +833,7 @@ which can secure your controller using annotations: .. code-block:: php + // ... use JMS\SecurityExtraBundle\Annotation\Secure; /** diff --git a/book/service_container.rst b/book/service_container.rst index d62064ca7e3..d235d30534e 100644 --- a/book/service_container.rst +++ b/book/service_container.rst @@ -78,7 +78,7 @@ we need it: use Acme\HelloBundle\Mailer; $mailer = new Mailer('sendmail'); - $mailer->send('ryan@foobar.net', ... ); + $mailer->send('ryan@foobar.net', ...); This is easy enough. The imaginary ``Mailer`` class allows us to configure the method used to deliver the email messages (e.g. ``sendmail``, ``smtp``, etc). @@ -150,7 +150,7 @@ shortcut method:: { // ... $mailer = $this->get('my_mailer'); - $mailer->send('ryan@foobar.net', ... ); + $mailer->send('ryan@foobar.net', ...); } } @@ -548,6 +548,7 @@ really good at delivering email messages, so we'll use it inside ``NewsletterMan to handle the actual delivery of the messages. This pretend class might look something like this:: + // src/Acme/HelloBundle/Newsletter/NewsletterManager.php namespace Acme\HelloBundle\Newsletter; use Acme\HelloBundle\Mailer; @@ -605,7 +606,7 @@ the service container gives us a much more appealing option: - + @@ -622,7 +623,7 @@ the service container gives us a much more appealing option: // ... $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager'); - $container->setDefinition('my_mailer', ... ); + $container->setDefinition('my_mailer', ...); $container->setDefinition('newsletter_manager', new Definition( '%newsletter_manager.class%', array(new Reference('my_mailer')) @@ -693,7 +694,7 @@ Injecting the dependency by the setter method just needs a change of syntax: - + @@ -712,7 +713,7 @@ Injecting the dependency by the setter method just needs a change of syntax: // ... $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager'); - $container->setDefinition('my_mailer', ... ); + $container->setDefinition('my_mailer', ...); $container->setDefinition('newsletter_manager', new Definition( '%newsletter_manager.class%' ))->addMethodCall('setMailer', array( @@ -753,7 +754,7 @@ it exists and do nothing if it doesn't: - + @@ -771,7 +772,7 @@ it exists and do nothing if it doesn't: // ... $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager'); - $container->setDefinition('my_mailer', ... ); + $container->setDefinition('my_mailer', ...); $container->setDefinition('newsletter_manager', new Definition( '%newsletter_manager.class%', array(new Reference('my_mailer', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)) diff --git a/book/templating.rst b/book/templating.rst index 081961a1350..bf0e295991f 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -613,7 +613,8 @@ syntax for controllers (i.e. **bundle**:**controller**:**action**): .. code-block:: html+jinja {# app/Resources/views/base.html.twig #} - ... + + {# ... #}