Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '2.0' into 2.1

Conflicts:
	cookbook/form/index.rst
	cookbook/map.rst.inc
	reference/forms/types/options/date_widget.rst.inc
  • Loading branch information...
commit 17eef6a8cb23370491dbbdefb4dd5c0729cc41f6 2 parents cd9eda4 + 87c0536
@weaverryan weaverryan authored
View
33 components/console/introduction.rst
@@ -160,6 +160,39 @@ You can also set these colors and options inside the tagname::
// bold text on a yellow background
$output->writeln('<bg=yellow;options=bold>foo</bg=yellow;options=bold>');
+Verbosity Levels
+~~~~~~~~~~~~~~~~
+
+The console has 3 levels of verbosity. These are defined in the
+:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
+
+================================== ===============================
+Option Value
+================================== ===============================
+OutputInterface::VERBOSITY_QUIET Do not output any messages
+OutputInterface::VERBOSITY_NORMAL The default verbosity level
+OutputInterface::VERBOSITY_VERBOSE Increased verbosity of messages
+================================== ===============================
+
+You can specify the quiet verbosity level with the ``--quiet`` or ``-q``
+option. The ``--verbose`` or ``-v`` option is used when you want an increased
+level of verbosity.
+
+.. tip::
+
+ The full exception stacktrace is printed if the ``VERBOSITY_VERBOSE``
+ level is used.
+
+It is possible to print a message in a command for only a specific verbosity
+level. For example::
+
+ if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
+ $output->writeln(...);
+ }
+
+When the quiet level is used, all output is suppressed as the default
+:method:`Symfony\Component\Console\Output::write<Symfony\\Component\\Console\\Output::write>`
+method returns without actually printing.
Using Command Arguments
-----------------------
View
8 components/dom_crawler.rst
@@ -278,16 +278,16 @@ To work with multi-dimensional fields::
<input name="multi[dimensional]" />
</form>
-You must specify the fully qualified name of the field::
+Pass an array of values::
// Set a single field
- $form->setValue('multi[0]', 'value');
+ $form->setValues(array('multi' => array('value')));
// Set multiple fields at once
- $form->setValue('multi', array(
+ $form->setValues(array('multi' => array(
1 => 'value',
'dimensional' => 'an other value'
- ));
+ )));
This is great, but it gets better! The ``Form`` object allows you to interact
with your form like a browser, selecting radio values, ticking checkboxes,
View
6 components/serializer.rst
@@ -90,7 +90,11 @@ use the Serializer service created before::
$person->setName('foo');
$person->setAge(99);
- $serializer->serialize($person, 'json'); // Output: {"name":"foo","age":99}
+ $jsonContent = $serializer->serialize($person, 'json');
+
+ // $jsonContent contains {"name":"foo","age":99}
+
+ echo $jsonContent; // or return it in a Response
The first parameter of the :method:`Symfony\\Component\\Serializer\\Serializer::serialize`
is the object to be serialized and the second is used to choose the proper encoder,
View
1  cookbook/form/index.rst
@@ -12,3 +12,4 @@ Form
create_form_type_extension
use_virtuals_forms
unit_testing
+ use_empty_data
View
84 cookbook/form/use_empty_data.rst
@@ -0,0 +1,84 @@
+.. index::
+ single: Form; Empty data
+
+How to configure Empty Data for a Form Class
+============================================
+
+The ``empty_data`` option allows you to specify an empty data set for your
+form class. This empty data set would be used if you bind your form, but
+haven't called ``setData()`` on your form or passed in data when you created
+you form. For example::
+
+ public function indexAction()
+ {
+ $blog = // ...
+
+ // $blog is passed in as the data, so the empty_data option is not needed
+ $form = $this->createForm(new BlogType(), $blog);
+
+ // no data is passed in, so empty_data is used to get the "starting data"
+ $form = $this->createForm(new BlogType());
+ }
+
+By default, ``empty_data`` is set to ``null``. Or, if you have specified
+a ``data_class`` option for your form class, it will default to a new instance
+of that class. That instance will be created by calling the constructor
+with no arguments.
+
+If you want to override this default behavior, there are two ways to do this.
+
+Option 1: Instantiate a new Class
+---------------------------------
+
+One reason you might use this option is if you want to use a constructor
+that takes arguments. Remember, the default ``data_class`` option calls
+that constructor with no arguments::
+
+ // src/Acme/DemoBundle/Form/Type/BlogType.php
+ // ...
+
+ use Symfony\Component\Form\AbstractType;
+ use Acme\DemoBundle\Entity\Blog;
+
+ class BlogType extends AbstractType
+ {
+ private $someDependency;
+
+ public function __construct($someDependency)
+ {
+ $this->someDependency = $someDependency;
+ }
+ // ...
+
+ public function getDefaultOptions()
+ {
+ return array(
+ 'empty_data' => new Blog($this->someDependency),
+ );
+ }
+ }
+
+You can instantiate your class however you want. In this example, we pass
+some dependency into the ``BlogType`` when we instantiate it, then use that
+to instantiate the ``Blog`` object. The point is, you can set ``empty_data``
+to the exact "new" object that you want to use.
+
+Option 2: Provide a Closure
+---------------------------
+
+Using a closure is the preferred method, since it will only create the object
+if it is needed.
+
+The closure must accept a ``FormInterface`` instance as the first argument::
+
+ use Symfony\Component\Form\FormInterface;
+ // ...
+
+ public function getDefaultOptions()
+ {
+ return array(
+ 'empty_data' => function (FormInterface $form) {
+ return new Blog($form->get('title')->getData());
+ },
+ );
+ }
View
1  cookbook/map.rst.inc
@@ -83,6 +83,7 @@
* :doc:`/cookbook/form/create_form_type_extension`
* :doc:`/cookbook/form/use_virtuals_forms`
* :doc:`/cookbook/form/unit_testing`
+ * :doc:`/cookbook/form/use_empty_data`
* (validation) :doc:`/cookbook/validation/custom_constraint`
* (doctrine) :doc:`/cookbook/doctrine/file_uploads`
View
5 reference/forms/types/options/_date_limitation.rst.inc
@@ -0,0 +1,5 @@
+.. caution::
+
+ If ``timestamp`` is used, ``DateType`` is limited to dates between
+ Fri, 13 Dec 1901 20:45:54 GMT and Tue, 19 Jan 2038 03:14:07 GMT on 32bit
+ systems. This is due to a `limitation in PHP itself <http://php.net/manual/en/function.date.php#refsect1-function.date-changelog>`_.
View
4 reference/forms/types/options/date_input.rst.inc
@@ -12,4 +12,6 @@ your underlying object. Valid values are:
* ``timestamp`` (e.g. ``1307232000``)
The value that comes back from the form will also be normalized back into
-this format.
+this format.
+
+.. include:: /reference/forms/types/options/_date_limitation.rst.inc
View
2  reference/forms/types/options/date_widget.rst.inc
@@ -12,3 +12,5 @@ The basic way in which this field should be rendered. Can be one of the followin
* ``single_text``: renders a single input of type date (text in Symfony 2.0). User's
input is validated based on the `format`_ option.
+
+.. include:: /reference/forms/types/options/_date_limitation.rst.inc
View
5 reference/forms/types/options/empty_data.rst.inc
@@ -20,3 +20,8 @@ value is selected, you can do it like this:
'empty_value' => 'Choose your gender',
'empty_data' => null
));
+
+.. note::
+
+ If you want to set the ``empty_data`` option for your entire form class,
+ see the cookbook article :doc:`/cookbook/form/use_empty_data`
Please sign in to comment.
Something went wrong with that request. Please try again.