diff --git a/best_practices/business-logic.rst b/best_practices/business-logic.rst index 23abb880c8e..b2d349ce2f5 100644 --- a/best_practices/business-logic.rst +++ b/best_practices/business-logic.rst @@ -81,7 +81,7 @@ Next, define a new service for that class. # app/config/services.yml services: # keep your service names short - slugger: + app.slugger: class: AppBundle\Utils\Slugger Traditionally, the naming convention for a service involved following the @@ -92,7 +92,8 @@ your code will be easier to read and use. .. best-practice:: The name of your application's services should be as short as possible, - ideally just one simple word. + but unique enough that you can search your project for the service if + you ever need to. Now you can use the custom slugger in any controller class, such as the ``AdminController``: @@ -104,7 +105,7 @@ Now you can use the custom slugger in any controller class, such as the // ... if ($form->isSubmitted() && $form->isValid()) { - $slug = $this->get('slugger')->slugify($post->getTitle()); + $slug = $this->get('app.slugger')->slugify($post->getTitle()); $post->setSlug($slug); // ... @@ -143,7 +144,7 @@ the class namespace as a parameter: slugger.class: AppBundle\Utils\Slugger services: - slugger: + app.slugger: class: "%slugger.class%" This practice is cumbersome and completely unnecessary for your own services: diff --git a/best_practices/forms.rst b/best_practices/forms.rst index 6d70561e914..883f2c8a998 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -157,29 +157,15 @@ There are a lot of ways to render your form, ranging from rendering the entire thing in one line to rendering each part of each field independently. The best way depends on how much customization you need. -The simplest way - which is especially useful during development - is to render -the form tags manually and then use ``form_widget()`` to render all of the fields: +One of the simplest ways - which is especially useful during development - +is to render the form tags and use ``form_widget()`` to render all of the +fields: .. code-block:: html+jinja -
+ {{ form_start(form, {'attr': {'class': 'my-form-class'} }) }} {{ form_widget(form) }} -
- -.. best-practice:: - - Don't use the ``form()`` or ``form_start()`` functions to render the - starting and ending form tags. - -Experienced Symfony developers will recognize that we're rendering the ``
`` -tags manually instead of using the ``form_start()`` or ``form()`` functions. -While those are convenient, they take away from some clarity with little -benefit. - -.. tip:: - - The exception is a delete form because it's really just one button and - so benefits from some of these extra shortcuts. + {{ form_end(form) }} If you need more control over how your fields are rendered, then you should remove the ``form_widget(form)`` function and render your fields individually. diff --git a/book/doctrine.rst b/book/doctrine.rst index 871695ff21d..e1f66134ed4 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1105,6 +1105,7 @@ Now you can see this new code in action! Imagine you're inside a controller:: $product = new Product(); $product->setName('Foo'); $product->setPrice(19.99); + $product->setDescription('Lorem ipsum dolor'); // relate this product to the category $product->setCategory($category); diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index 581f8cc8aff..a8e10eb6f04 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -367,7 +367,7 @@ on the requested URI: require_once 'controllers.php'; // route the request internally - $uri = $_SERVER['REQUEST_URI']; + $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ('/index.php' == $uri) { list_action(); } elseif ('/index.php/show' == $uri && isset($_GET['id'])) { diff --git a/book/security.rst b/book/security.rst index f9d75d6f913..13d2057cf61 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1546,9 +1546,6 @@ do the following: ), )); -.. versionadded:: 2.2 - The BCrypt encoder was introduced in Symfony 2.2. - You can now calculate the hashed password either programmatically (e.g. ``password_hash('ryanpass', PASSWORD_BCRYPT, array('cost' => 12));``) or via some online tool. diff --git a/book/templating.rst b/book/templating.rst index 5c429599518..4d088768464 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -1487,12 +1487,33 @@ in a JavaScript string, use the ``js`` context: Debugging --------- -When using PHP, you can use :phpfunction:`var_dump` if you need to quickly find -the value of a variable passed. This is useful, for example, inside your -controller. The same can be achieved when using Twig thanks to the Debug -extension. +When using PHP, you can use the +:ref:`dump() function from the VarDumper component ` +if you need to quickly find the value of a variable passed. This is useful, +for example, inside your controller:: -Template parameters can then be dumped using the ``dump`` function: + // src/AppBundle/Controller/ArticleController.php + namespace AppBundle\Controller; + + // ... + + class ArticleController extends Controller + { + public function recentListAction() + { + $articles = ...; + dump($articles); + + // ... + } + } + +.. note:: + + The output of the ``dump()`` function is then rendered in the web developer + toolbar. + +The same mechanism can be used in Twig templates thanks to ``dump`` function: .. code-block:: html+jinja diff --git a/components/filesystem/introduction.rst b/components/filesystem/introduction.rst index 8990198aa41..44603184c0c 100644 --- a/components/filesystem/introduction.rst +++ b/components/filesystem/introduction.rst @@ -6,11 +6,6 @@ The Filesystem Component The Filesystem component provides basic utilities for the filesystem. -.. versionadded:: 2.1 - The Filesystem component was introduced in Symfony 2.1. Previously, the - ``Filesystem`` class was located in the HttpKernel component. - - .. tip:: A lock handler feature was introduce in symfony 2.6. diff --git a/components/form/introduction.rst b/components/form/introduction.rst index 05d4a0d1584..09c947429b5 100644 --- a/components/form/introduction.rst +++ b/components/form/introduction.rst @@ -663,29 +663,45 @@ and the errors will display next to the fields on error. Accessing Form Errors ~~~~~~~~~~~~~~~~~~~~~ +.. versionadded:: 2.5 + Before Symfony 2.5, ``getErrors()`` returned an array of ``FormError`` + objects. The return value was changed to ``FormErrorIterator`` in Symfony + 2.5. + +.. versionadded:: 2.5 + The ``$deep`` and ``$flatten`` arguments were introduced in Symfony 2.5. + You can use the :method:`Symfony\\Component\\Form\\FormInterface::getErrors` -method to access the list of errors. Each element is a :class:`Symfony\\Component\\Form\\FormError` -object:: +method to access the list of errors. It returns a +:class:`Symfony\\Component\\Form\\FormErrorIterator` instance:: $form = ...; // ... - // an array of FormError objects, but only errors attached to this form level (e.g. "global errors) + // a FormErrorIterator instance, but only errors attached to this form level (e.g. "global errors) $errors = $form->getErrors(); - // an array of FormError objects, but only errors attached to the "firstName" field + // a FormErrorIterator instance, but only errors attached to the "firstName" field $errors = $form['firstName']->getErrors(); - // a string representation of all errors of the whole form tree - $errors = $form->getErrorsAsString(); + // a FormErrorIterator instance in a flattened structure + // use getOrigin() to determine the form causing the error + $errors = $form->getErrors(true); -.. note:: + // a FormErrorIterator instance representing the form tree structure + $errors = $form->getErrors(true, false); + +.. tip:: + + In older Symfony versions, ``getErrors()`` returned an array. To use the + errors the same way in Symfony 2.5 or newer, you have to pass them to + PHP's :phpfunction:`iterator_to_array` function:: + + $errorsAsArray = iterator_to_array($form->getErrors()); - If you enable the :ref:`error_bubbling ` - option on a field, calling ``getErrors()`` on the parent form will include - errors from that field. However, there is no way to determine which field - an error was originally attached to. + This is useful, for example, if you want to use PHP's ``array_`` function + on the form errors. .. _Packagist: https://packagist.org/packages/symfony/form .. _Twig: http://twig.sensiolabs.org diff --git a/components/var_dumper/introduction.rst b/components/var_dumper/introduction.rst index 990a4ad3b80..06c7eb5816d 100644 --- a/components/var_dumper/introduction.rst +++ b/components/var_dumper/introduction.rst @@ -20,6 +20,8 @@ You can install the component in 2 different ways: * :doc:`Install it via Composer ` (``symfony/var-dumper`` on `Packagist`_); * Use the official Git repository (https://github.com/symfony/var-dumper). +.. _components-var-dumper-dump: + The dump() Function ------------------- diff --git a/contributing/documentation/overview.rst b/contributing/documentation/overview.rst index 0bf56f0820f..e610df1b994 100644 --- a/contributing/documentation/overview.rst +++ b/contributing/documentation/overview.rst @@ -170,7 +170,7 @@ Now you can **sync your fork** by executing the following command: $ git merge upstream/2.3 This command will update the ``2.3`` branch, which is the one you used to -create the new branch for your changes. If have used another base branch, +create the new branch for your changes. If you have used another base branch, e.g. ``master``, replace the ``2.3`` with the appropriate branch name. Great! Now you can proceed by following the same steps explained in the previous diff --git a/cookbook/debugging.rst b/cookbook/debugging.rst index 372fb707931..98fae25bad8 100644 --- a/cookbook/debugging.rst +++ b/cookbook/debugging.rst @@ -47,8 +47,6 @@ below:: $loader = require_once __DIR__.'/../app/autoload.php'; require_once __DIR__.'/../app/AppKernel.php'; - use Symfony\Component\HttpFoundation\Request; - $kernel = new AppKernel('dev', true); // $kernel->loadClassCache(); $request = Request::createFromGlobals(); diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index df8ab95ecc2..9793a67d357 100644 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -463,9 +463,9 @@ we talk about next!). .. caution:: - If no ``addTag`` **and** ``removeTag`` method is found, the form will - still use ``setTag`` even if ``by_reference`` is ``false``. You'll learn - more about the ``removeTag`` method later in this article. + You have to create **both** ``addTag`` and ``removeTag`` methods, + otherwise the form will still use ``setTag`` even if ``by_reference`` is ``false``. + You'll learn more about the ``removeTag`` method later in this article. .. sidebar:: Doctrine: Cascading Relations and saving the "Inverse" side diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 781bc2744d1..8a09b5bcff8 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -67,11 +67,19 @@ just one line: .. code-block:: jinja + {# renders all fields #} {{ form_widget(form) }} + {# renders all fields *and* the form start and end tags #} + {{ form(form) }} + .. code-block:: php - widget($form); ?> + + widget($form) ?> + + + form($form) ?> The remainder of this recipe will explain how every part of the form's markup can be modified at several different levels. For more information about form @@ -93,9 +101,18 @@ rendering a form. In other words, if you want to customize one portion of how a form is rendered, you'll import a *theme* which contains a customization of the appropriate form fragments. -Symfony comes with a default theme (`form_div_layout.html.twig`_ in Twig and -``FrameworkBundle:Form`` in PHP) that defines each and every fragment needed -to render every part of a form. +Symfony comes with four **built-in form themes** that define each and every +fragment needed to render every part of a form: + +* `form_div_layout.html.twig`_, wraps each form field inside a ``
`` element. +* `form_table_layout.html.twig`_, wraps the entire form inside a ```` + element and each form field inside a ```` element. +* `bootstrap_3_layout.html.twig`_, wraps each form field inside a ``
`` element + with the appropriate CSS classes to apply the default `Bootstrap 3 CSS framework`_ + styles. +* `bootstrap_3_horizontal_layout.html.twig`_, it's similar to the previous theme, + but the CSS classes applied are the ones used to display the forms horizontally + (i.e. the label and the widget in the same row). In the next section you will learn how to customize a theme by overriding some or all of its fragments. @@ -1059,3 +1076,7 @@ The array passed as the second argument contains form "variables". For more details about this concept in Twig, see :ref:`twig-reference-form-variables`. .. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +.. _`form_table_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig +.. _`bootstrap_3_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig +.. _`bootstrap_3_horizontal_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig +.. _`Bootstrap 3 CSS framework`: http://getbootstrap.com/ diff --git a/cookbook/routing/slash_in_parameter.rst b/cookbook/routing/slash_in_parameter.rst index 64f1a27c08d..db2078a2bc3 100644 --- a/cookbook/routing/slash_in_parameter.rst +++ b/cookbook/routing/slash_in_parameter.rst @@ -5,12 +5,12 @@ How to Allow a "/" Character in a Route Parameter ================================================= Sometimes, you need to compose URLs with parameters that can contain a slash -``/``. For example, take the classic ``/hello/{name}`` route. By default, +``/``. For example, take the classic ``/hello/{username}`` route. By default, ``/hello/Fabien`` will match this route but not ``/hello/Fabien/Kris``. This is because Symfony uses this character as separator between route parts. This guide covers how you can modify a route so that ``/hello/Fabien/Kris`` -matches the ``/hello/{name}`` route, where ``{name}`` equals ``Fabien/Kris``. +matches the ``/hello/{username}`` route, where ``{username}`` equals ``Fabien/Kris``. Configure the Route ------------------- @@ -27,10 +27,10 @@ a more permissive regex path. .. code-block:: yaml _hello: - path: /hello/{name} + path: /hello/{username} defaults: { _controller: AcmeDemoBundle:Demo:hello } requirements: - name: .+ + username: .+ .. code-block:: xml @@ -40,9 +40,9 @@ a more permissive regex path. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + AcmeDemoBundle:Demo:hello - .+ + .+ @@ -52,10 +52,10 @@ a more permissive regex path. use Symfony\Component\Routing\Route; $collection = new RouteCollection(); - $collection->add('_hello', new Route('/hello/{name}', array( + $collection->add('_hello', new Route('/hello/{username}', array( '_controller' => 'AcmeDemoBundle:Demo:hello', ), array( - 'name' => '.+', + 'username' => '.+', ))); return $collection; @@ -75,4 +75,4 @@ a more permissive regex path. } } -That's it! Now, the ``{name}`` parameter can contain the ``/`` character. +That's it! Now, the ``{username}`` parameter can contain the ``/`` character. diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 144d7809f48..398138398ce 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -877,7 +877,3 @@ then instead of these properties being checked, your ``isEqualTo`` method is simply called, and you can check whatever properties you want. Unless you understand this, you probably *won't* need to implement this interface or worry about it. - -.. versionadded:: 2.1 - In Symfony 2.1, the ``equals`` method was removed from ``UserInterface`` - and the ``EquatableInterface`` was introduced in its place. diff --git a/cookbook/security/target_path.rst b/cookbook/security/target_path.rst index 6f7a0536da1..c6c97de7b21 100644 --- a/cookbook/security/target_path.rst +++ b/cookbook/security/target_path.rst @@ -67,4 +67,4 @@ Next, create your own ``ExceptionListener``:: } } -Add as much or few logic here as required for your scenario! +Add as much or as little logic here as required for your scenario! diff --git a/reference/configuration/assetic.rst b/reference/configuration/assetic.rst index f85346394a8..8126d03fd49 100644 --- a/reference/configuration/assetic.rst +++ b/reference/configuration/assetic.rst @@ -4,8 +4,8 @@ AsseticBundle Configuration ("assetic") ======================================= -Full default Configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~ +Full Default Configuration +-------------------------- .. configuration-block:: diff --git a/reference/configuration/doctrine.rst b/reference/configuration/doctrine.rst index 6f8fbf73562..1d0b00cde72 100644 --- a/reference/configuration/doctrine.rst +++ b/reference/configuration/doctrine.rst @@ -5,7 +5,7 @@ DoctrineBundle Configuration ("doctrine") ========================================= -Full default configuration +Full Default Configuration -------------------------- .. configuration-block:: @@ -180,8 +180,10 @@ Full default configuration + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/doctrine + http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> @@ -209,16 +211,44 @@ Full default configuration Acme\HelloBundle\MyCustomType - - - + + + + + - Acme\HelloBundle\DQL\StringFunction - Acme\HelloBundle\DQL\NumericFunction - Acme\HelloBundle\DQL\DatetimeFunction + + Acme\HelloBundle\DQL\StringFunction + + + + Acme\HelloBundle\DQL\NumericFunction + + + + Acme\HelloBundle\DQL\DatetimeFunction + + + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/doctrine + http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" + > + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/monolog + http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" + > `". * ``check_path`` (type: ``string``, default: ``/login_check``) @@ -280,8 +280,8 @@ The Login Form and Process a separate firewall just for ``check_path`` URL). * ``use_forward`` (type: ``Boolean``, default: ``false``) - If you'd like the user to be forwarded to the login form instead of being - redirected, set this option to ``true``. + If you'd like the user to be forwarded to the login form instead of + being redirected, set this option to ``true``. * ``username_parameter`` (type: ``string``, default: ``_username``) This is the field name that you should give to the username field of diff --git a/reference/forms/types/options/with_minutes.rst.inc b/reference/forms/types/options/with_minutes.rst.inc index 48e6cdddcaf..60ad9b94515 100644 --- a/reference/forms/types/options/with_minutes.rst.inc +++ b/reference/forms/types/options/with_minutes.rst.inc @@ -1,9 +1,6 @@ with_minutes ~~~~~~~~~~~~ -.. versionadded:: 2.2 - The ``with_minutes`` option was introduced in Symfony 2.2. - **type**: ``Boolean`` **default**: ``true`` Whether or not to include minutes in the input. This will result in an additional diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 8a7f5ad33e3..80078b2aa15 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -7,15 +7,19 @@ Symfony Twig Extensions ======================= Twig is the default template engine for Symfony. By itself, it already contains -a lot of built-in functions, filters, tags and tests (`http://twig.sensiolabs.org/documentation`_ -then scroll to the bottom). +a lot of built-in functions, filters, tags and tests (learn more about them +from the the `Twig Reference`_). -Symfony adds more custom extension on top of Twig to integrate some components -into the Twig templates. Below is information about all the custom functions, -filters, tags and tests that are added when using the Symfony Core Framework. +Symfony adds more custom extensions on top of Twig to integrate some components +into the Twig templates. You can find more information about the custom +:ref:`functions `, :ref:`filters `, +:ref:`tags ` and :ref:`tests ` +that are added when using the Symfony Core Framework. There may also be tags in bundles you use that aren't listed here. +.. _reference-twig-functions: + Functions --------- @@ -24,10 +28,6 @@ Functions render ~~~~~~ -.. versionadded:: 2.2 - The ``render()`` function was introduced in Symfony 2.2. Prior, the - ``{% render %}`` tag was used and had a different signature. - .. code-block:: jinja {{ render(uri, options) }} @@ -40,7 +40,7 @@ render Renders the fragment for the given controller (using the `controller`_ function) or URI. For more information, see :ref:`templating-embedding-controller`. -The render strategy can be specified in the ``strategy`` key of the options. +The render strategy can be specified in the ``strategy`` key of the options. .. tip:: @@ -65,7 +65,7 @@ Generates an ESI tag when possible or falls back to the behaviour of .. tip:: The URI can be generated by other functions, like `path`_ and `url`_. - + .. tip:: The ``render_esi()`` function is an example of the shortcut functions @@ -76,9 +76,6 @@ Generates an ESI tag when possible or falls back to the behaviour of controller ~~~~~~~~~~ -.. versionadded:: 2.2 - The ``controller()`` function was introduced in Symfony 2.2. - .. code-block:: jinja {{ controller(controller, attributes, query) }} @@ -367,6 +364,8 @@ expression Creates an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` in Twig. See ":ref:`Template Expressions `". +.. _reference-twig-filters: + Filters ------- @@ -564,6 +563,8 @@ file_link Generates a link to the provided file (and optionally line number) using a preconfigured scheme. +.. _reference-twig-tags: + Tags ---- @@ -643,6 +644,8 @@ stopwatch This will time the run time of the code inside it and put that on the timeline of the WebProfilerBundle. +.. _reference-twig-tests: + Tests ----- @@ -692,5 +695,5 @@ Those bundles can have other Twig extensions: ``{% image %}`` tags. You can read more about them in :doc:`the Assetic Documentation `. +.. _`Twig Reference`: http://twig.sensiolabs.org/documentation#reference .. _`the official Twig Extensions documentation`: http://twig.sensiolabs.org/doc/extensions/index.html -.. _`http://twig.sensiolabs.org/documentation`: http://twig.sensiolabs.org/documentation