diff --git a/book/doctrine.rst b/book/doctrine.rst index 4df99b617be..0d5f9141eb2 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -953,8 +953,8 @@ To relate the ``Category`` and ``Product`` entities, start by creating a products: targetEntity: Product mappedBy: category - # don't forget to init the collection in the __construct() method - # of the entity + # Don't forget to initialize the collection in + # the __construct() method of the entity .. code-block:: xml @@ -1096,7 +1096,7 @@ table, and ``product.category_id`` column, and new foreign key: .. note:: - This task should only be really used during development. For a more robust + This command should only be used during development. For a more robust method of systematically updating your production database, read about `migrations`_. @@ -1187,7 +1187,7 @@ You can also query in the other direction:: // ... } -In this case, the same things occurs: you first query out for a single ``Category`` +In this case, the same things occur: you first query out for a single ``Category`` object, and then Doctrine makes a second query to retrieve the related ``Product`` objects, but only once/if you ask for them (i.e. when you call ``->getProducts()``). The ``$products`` variable is an array of all ``Product`` objects that relate diff --git a/book/forms.rst b/book/forms.rst index d5c969b8d1c..5f8c0b53ac3 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -212,8 +212,8 @@ Handling Form Submissions The second job of a form is to translate user-submitted data back to the properties of an object. To make this happen, the submitted data from the -user must be written into the form. Add the following functionality to your -controller:: +user must be written into the Form object. Add the following functionality to +your controller:: // ... use Symfony\Component\HttpFoundation\Request; @@ -679,9 +679,14 @@ the documentation for each type. The most common option is the ``required`` option, which can be applied to any field. By default, the ``required`` option is set to ``true``, meaning that HTML5-ready browsers will apply client-side validation if the field - is left blank. If you don't want this behavior, either set the ``required`` - option on your field to ``false`` or - :ref:`disable HTML5 validation `. + is left blank. If you don't want this behavior, either + :ref:`disable HTML5 validation ` + or set the ``required`` option on your field to ``false``:: + + ->add('dueDate', 'date', array( + 'widget' => 'single_text', + 'required' => false + )) Also note that setting the ``required`` option to ``true`` will **not** result in server-side validation to be applied. In other words, if a @@ -920,7 +925,7 @@ specify it: Some field types have additional rendering options that can be passed to the widget. These options are documented with each type, but one common -options is ``attr``, which allows you to modify attributes on the form element. +option is ``attr``, which allows you to modify attributes on the form element. The following would add the ``task_field`` class to the rendered input text field: diff --git a/book/templating.rst b/book/templating.rst index 4447b6198a6..4261da5b3e9 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -201,7 +201,7 @@ First, build a base layout file: - + {% block title %}Test Application{% endblock %} @@ -226,7 +226,7 @@ First, build a base layout file: - + <?php $view['slots']->output('title', 'Test Application') ?> @@ -311,7 +311,7 @@ output might look like this: - + My cool blog posts diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 18d05ebfb1d..6dce09de7d6 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -243,7 +243,7 @@ directly in the template that's actually rendering the form. .. code-block:: html+twig - {% extends '::base.html.twig' %} + {% extends 'base.html.twig' %} {% form_theme form _self %} @@ -282,7 +282,7 @@ can now re-use the form customization across many templates: .. code-block:: html+twig - {# app/Resources/views/Form/fields.html.twig #} + {# app/Resources/views/form/fields.html.twig #} {% block integer_widget %}
{% set type = type|default('number') %} @@ -298,7 +298,7 @@ tell Symfony to use the template via the ``form_theme`` tag: .. code-block:: html+twig - {% form_theme form 'AppBundle:Form:fields.html.twig' %} + {% form_theme form 'form/fields.html.twig' %} {{ form_widget(form.age) }} @@ -314,13 +314,12 @@ name of all the templates as an array using the ``with`` keyword: .. code-block:: html+twig - {% form_theme form with ['::common.html.twig', ':Form:fields.html.twig', - 'AppBundle:Form:fields.html.twig'] %} + {% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %} {# ... #} -The templates can be located at different bundles and they can even be stored -at the global ``app/Resources/views/`` directory. +The templates can also be located in different bundles, use the functional name +to reference these templates, e.g. ``AcmeFormExtraBundle:form:fields.html.twig``. Child Forms ........... @@ -329,16 +328,16 @@ You can also apply a form theme to a specific child of your form: .. code-block:: html+twig - {% form_theme form.child 'AppBundle:Form:fields.html.twig' %} + {% form_theme form.child 'form/fields.html.twig' %} This is useful when you want to have a custom theme for a nested form that's different than the one of your main form. Just specify both your themes: .. code-block:: html+twig - {% form_theme form 'AppBundle:Form:fields.html.twig' %} + {% form_theme form 'form/fields.html.twig' %} - {% form_theme form.child 'AppBundle:Form:fields_child.html.twig' %} + {% form_theme form.child 'form/fields_child.html.twig' %} .. _cookbook-form-php-theming: @@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment. .. code-block:: html+php - +
- block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?> + block( + $form, + 'form_widget_simple', + array('type' => isset($type) ? $type : "number") + ) ?>
Now that you've created the customized form template, you need to tell Symfony @@ -367,7 +370,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method: .. code-block:: php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> widget($form['age']) ?> @@ -380,7 +383,14 @@ method: .. code-block:: php - setTheme($form['child'], 'AppBundle:Form/Child'); ?> + setTheme($form['child'], ':form'); ?> + +.. note:: + + The ``:form`` syntax is based on the functional names for templates: + ``Bundle:Directory``. As the form directory lives in the + ``app/Resources/views`` directory, the ``Bundle`` part is empty, resulting + in ``:form``. .. _cookbook-form-twig-import-base-blocks: @@ -454,8 +464,8 @@ Twig ~~~~ By using the following configuration, any customized form blocks inside the -``AppBundle:Form:fields.html.twig`` template will be used globally when a -form is rendered. +``form/fields.html.twig`` template will be used globally when a form is +rendered. .. configuration-block:: @@ -465,7 +475,7 @@ form is rendered. twig: form: resources: - - 'AppBundle:Form:fields.html.twig' + - 'form/fields.html.twig' # ... .. code-block:: xml @@ -473,7 +483,7 @@ form is rendered. - AppBundle:Form:fields.html.twig + form/fields.html.twig @@ -484,7 +494,7 @@ form is rendered. $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - 'AppBundle:Form:fields.html.twig', + 'form/fields.html.twig', ), ), @@ -666,7 +676,7 @@ customize the ``name`` field only: .. code-block:: html+php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> widget($form['name']); ?> @@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method: .. code-block:: html+php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> row($form['name']); ?>