From 485b52957f453c6eb2672bfa285c0c4d9433250f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 11:12:54 +0100 Subject: [PATCH 001/145] Removed duplicated DQL documentation The doctrine docs already has a big great documentation on this. There is no reason to duplicate it in the sf docs. This commit removes everything except a simple example. It also moves the sentence about the return result above, since that makes more sense now the getSingleResult example is removed. --- book/doctrine.rst | 55 ++++------------------------------------------- 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 026a3b4f977..d2b9387611e 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -728,65 +728,18 @@ a controller, do the following:: $products = $query->getResult(); +The ``getResult()`` method returns an array of results. + If you're comfortable with SQL, then DQL should feel very natural. The biggest difference is that you need to think in terms of "objects" instead of rows -in a database. For this reason, you select *from* ``AcmeStoreBundle:Product`` -and then alias it as ``p``. - -The ``getResult()`` method returns an array of results. If you're querying -for just one object, you can use the ``getSingleResult()`` method instead:: - - $product = $query->getSingleResult(); - -.. caution:: - - The ``getSingleResult()`` method throws a ``Doctrine\ORM\NoResultException`` - exception if no results are returned and a ``Doctrine\ORM\NonUniqueResultException`` - if *more* than one result is returned. If you use this method, you may - need to wrap it in a try-catch block and ensure that only one result is - returned (if you're querying on something that could feasibly return - more than one result):: - - $query = $em->createQuery('SELECT ...') - ->setMaxResults(1); - - try { - $product = $query->getSingleResult(); - } catch (\Doctrine\Orm\NoResultException $e) { - $product = null; - } - // ... +in a database. For this reason, you select *from* the ``AcmeStoreBundle:Product`` +*object* and then alias it as ``p``. The DQL syntax is incredibly powerful, allowing you to easily join between entities (the topic of :ref:`relations ` will be covered later), group, etc. For more information, see the official Doctrine `Doctrine Query Language`_ documentation. -.. sidebar:: Setting Parameters - - Take note of the ``setParameter()`` method. When working with Doctrine, - it's always a good idea to set any external values as "placeholders", - which was done in the above query: - - .. code-block:: text - - ... WHERE p.price > :price ... - - You can then set the value of the ``price`` placeholder by calling the - ``setParameter()`` method:: - - ->setParameter('price', '19.99') - - Using parameters instead of placing values directly in the query string - is done to prevent SQL injection attacks and should *always* be done. - If you're using multiple parameters, you can set their values at once - using the ``setParameters()`` method:: - - ->setParameters(array( - 'price' => '19.99', - 'name' => 'Foo', - )) - Using Doctrine's Query Builder ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 1ec68feb0e2da8742c5b4547ebf4f0af955bf988 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 11:17:17 +0100 Subject: [PATCH 002/145] Minor tweaks to Repository section --- book/doctrine.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index d2b9387611e..f78be755922 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -772,10 +772,10 @@ Custom Repository Classes In the previous sections, you began constructing and using more complex queries from inside a controller. In order to isolate, test and reuse these queries, -it's a good idea to create a custom repository class for your entity and +it's a good practise to create a custom repository class for your entity and add methods with your query logic there. -To do this, add the name of the repository class to your mapping definition. +To do this, add the name of the repository class to your mapping definition: .. configuration-block:: From 22bb029c0556ee3392b71b0778e83e944d501f5f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:08:53 +0100 Subject: [PATCH 003/145] Minor tweak to configuration section --- book/doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index f78be755922..bbce8ad9ff6 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1253,7 +1253,7 @@ Configuration Doctrine is highly configurable, though you probably won't ever need to worry about most of its options. To find out more about configuring Doctrine, see -the Doctrine section of the :doc:`reference manual `. +the Doctrine section of the :doc:`config reference `. Lifecycle Callbacks ------------------- From 13edbcc403cb0de694a8ea4f9b14f417bde54ca2 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:11:41 +0100 Subject: [PATCH 004/145] Removed some duplicated Livecycle docs The list is also included in the doctrine docs. There is no need to duplicate that in the sf docs. And if it's usefull, it certainly isn't when there is no more documentation about their meaning. --- book/doctrine.rst | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index bbce8ad9ff6..c30cc8e05bd 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1265,7 +1265,7 @@ stages of the lifecycle of an entity (e.g. the entity is inserted, updated, deleted, etc). If you're using annotations for your metadata, start by enabling the lifecycle -callbacks. This is not necessary if you're using YAML or XML for your mapping: +callbacks. This is not necessary if you're using YAML or XML for your mapping. .. code-block:: php-annotations @@ -1328,20 +1328,8 @@ the current date, only when the entity is first persisted (i.e. inserted): Now, right before the entity is first persisted, Doctrine will automatically call this method and the ``createdAt`` field will be set to the current date. - -This can be repeated for any of the other lifecycle events, which include: - -* ``preRemove`` -* ``postRemove`` -* ``prePersist`` -* ``postPersist`` -* ``preUpdate`` -* ``postUpdate`` -* ``postLoad`` -* ``loadClassMetadata`` - -For more information on what these lifecycle events mean and lifecycle callbacks -in general, see Doctrine's `Lifecycle Events documentation`_ +For more information on other lifecycle events and lifecycle callbacks in +general, see Doctrine's `Lifecycle Events documentation`_. .. sidebar:: Lifecycle Callbacks and Event Listeners From c95a68d41cae07b7dc5bc7022b4b3134f8d69946 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:15:13 +0100 Subject: [PATCH 005/145] Removed "Doctrine Extensions" section It's enough to add it to the "Read more" list, there is no need to introduce each cookbook article in a seperate section. --- book/doctrine.rst | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index c30cc8e05bd..a68a2186b3b 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1344,17 +1344,6 @@ general, see Doctrine's `Lifecycle Events documentation`_. or subscriber and give it access to whatever resources you need. For more information, see :doc:`/cookbook/doctrine/event_listeners_subscribers`. -Doctrine Extensions: Timestampable, Sluggable, etc. ---------------------------------------------------- - -Doctrine is quite flexible, and a number of third-party extensions are available -that allow you to easily perform repeated and common tasks on your entities. -These include thing such as *Sluggable*, *Timestampable*, *Loggable*, *Translatable*, -and *Tree*. - -For more information on how to find and use these extensions, see the cookbook -article about :doc:`using common Doctrine extensions `. - .. _book-doctrine-field-types: Doctrine Field Types Reference From 88aa347e80c76f9c4cabe03340ddeb7b68f87e75 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:16:39 +0100 Subject: [PATCH 006/145] Removed types list This is really doctrine specific, the sf docs should not document this, kind of SoC for docs :wink:. --- book/doctrine.rst | 102 +--------------------------------------------- 1 file changed, 2 insertions(+), 100 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index a68a2186b3b..7e78b106307 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1351,106 +1351,8 @@ Doctrine Field Types Reference Doctrine comes with a large number of field types available. Each of these maps a PHP data type to a specific column type in whatever database you're -using. The following types are supported in Doctrine: - -* **Strings** - - * ``string`` (used for shorter strings) - * ``text`` (used for larger strings) - -* **Numbers** - - * ``integer`` - * ``smallint`` - * ``bigint`` - * ``decimal`` - * ``float`` - -* **Dates and Times** (use a `DateTime`_ object for these fields in PHP) - - * ``date`` - * ``time`` - * ``datetime`` - * ``datetimetz`` - -* **Other Types** - - * ``boolean`` - * ``object`` (serialized and stored in a ``CLOB`` field) - * ``array`` (serialized and stored in a ``CLOB`` field) - * ``blob`` (mapped to a resource stream) - * ``simple_array`` (serialized using :phpfunction:`implode()` and :phpfunction:`explode()`, - with a comma as delimiter, and stored in a ``CLOB`` field) - * ``json_array`` (serialized using :phpfunction:`json_encode()` and :phpfunction:`json_decode()`, - and stored in a ``CLOB`` field) - * ``guid`` - -For more information, see Doctrine's `Mapping Types documentation`_. - -Field Options -~~~~~~~~~~~~~ - -Each field can have a set of options applied to it. The available options -include ``type`` (defaults to ``string``), ``name``, ``length``, ``unique`` -and ``nullable``. Take a few examples: - -.. configuration-block:: - - .. code-block:: php-annotations - - /** - * A string field with length 255 that cannot be null - * (reflecting the default values for the "type", "length" - * and *nullable* options) - * - * @ORM\Column() - */ - protected $name; - - /** - * A string field of length 150 that persists to an "email_address" column - * and has a unique index. - * - * @ORM\Column(name="email_address", unique=true, length=150) - */ - protected $email; - - .. code-block:: yaml - - fields: - # A string field length 255 that cannot be null - # (reflecting the default values for the "length" and *nullable* options) - # type attribute is necessary in YAML definitions - name: - type: string - - # A string field of length 150 that persists to an "email_address" column - # and has a unique index. - email: - type: string - column: email_address - length: 150 - unique: true - - .. code-block:: xml - - - - - -.. note:: - - There are a few more options not listed here. For more details, see - Doctrine's `Property Mapping documentation`_ +using. To see a list of all available types and more information, see +Doctrine's `Mapping Types documentation`_. .. index:: single: Doctrine; ORM console commands From 2c68f04583585b26e6e36e340b29161bc4dbbf2b Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:22:31 +0100 Subject: [PATCH 007/145] Moved commands to cookbook It's not really basic information. All important commands are already discussed in the rest of the chapter. The rest are just usefull commands, which is a perfect topic for a cookbook. --- book/doctrine.rst | 62 +---------------------------------- cookbook/doctrine/console.rst | 60 +++++++++++++++++++++++++++++++++ cookbook/doctrine/index.rst | 1 + cookbook/map.rst.inc | 1 + 4 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 cookbook/doctrine/console.rst diff --git a/book/doctrine.rst b/book/doctrine.rst index 7e78b106307..8abdaaf4958 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1354,67 +1354,6 @@ maps a PHP data type to a specific column type in whatever database you're using. To see a list of all available types and more information, see Doctrine's `Mapping Types documentation`_. -.. index:: - single: Doctrine; ORM console commands - single: CLI; Doctrine ORM - -Console Commands ----------------- - -The Doctrine2 ORM integration offers several console commands under the -``doctrine`` namespace. To view the command list you can run the console -without any arguments: - -.. code-block:: bash - - $ php app/console - -A list of available commands will print out, many of which start with the -``doctrine:`` prefix. You can find out more information about any of these -commands (or any Symfony command) by running the ``help`` command. For example, -to get details about the ``doctrine:database:create`` task, run: - -.. code-block:: bash - - $ php app/console help doctrine:database:create - -Some notable or interesting tasks include: - -* ``doctrine:ensure-production-settings`` - checks to see if the current - environment is configured efficiently for production. This should always - be run in the ``prod`` environment: - - .. code-block:: bash - - $ php app/console doctrine:ensure-production-settings --env=prod - -* ``doctrine:mapping:import`` - allows Doctrine to introspect an existing - database and create mapping information. For more information, see - :doc:`/cookbook/doctrine/reverse_engineering`. - -* ``doctrine:mapping:info`` - tells you all of the entities that Doctrine - is aware of and whether or not there are any basic errors with the mapping. - -* ``doctrine:query:dql`` and ``doctrine:query:sql`` - allow you to execute - DQL or SQL queries directly from the command line. - -.. note:: - - To be able to load data fixtures to your database, you will need to have - the DoctrineFixturesBundle bundle installed. To learn how to do it, - read the ":doc:`/bundles/DoctrineFixturesBundle/index`" entry of the - documentation. - -.. tip:: - - This page shows working with Doctrine within a controller. You may also - want to work with Doctrine elsewhere in your application. The - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` - method of the controller returns the ``doctrine`` service, you can work with - this in the same way elsewhere by injecting this into your own - services. See :doc:`/book/service_container` for more on creating - your own services. - Summary ------- @@ -1434,6 +1373,7 @@ For more information about Doctrine, see the *Doctrine* section of the * :doc:`/bundles/DoctrineFixturesBundle/index` * :doc:`/cookbook/doctrine/common_extensions` +* :doc:`/cookbook/doctrine/console` .. _`Doctrine`: http://www.doctrine-project.org/ .. _`MongoDB`: http://www.mongodb.org/ diff --git a/cookbook/doctrine/console.rst b/cookbook/doctrine/console.rst new file mode 100644 index 00000000000..b48cd3e3f3c --- /dev/null +++ b/cookbook/doctrine/console.rst @@ -0,0 +1,60 @@ +.. index:: + single: Doctrine; ORM console commands + single: CLI; Doctrine ORM + +Console Commands +---------------- + +The Doctrine2 ORM integration offers several console commands under the +``doctrine`` namespace. To view the command list you can run the console +without any arguments: + +.. code-block:: bash + + $ php app/console + +A list of available commands will print out, many of which start with the +``doctrine:`` prefix. You can find out more information about any of these +commands (or any Symfony command) by running the ``help`` command. For example, +to get details about the ``doctrine:database:create`` task, run: + +.. code-block:: bash + + $ php app/console help doctrine:database:create + +Some notable or interesting tasks include: + +* ``doctrine:ensure-production-settings`` - checks to see if the current + environment is configured efficiently for production. This should always + be run in the ``prod`` environment: + + .. code-block:: bash + + $ php app/console doctrine:ensure-production-settings --env=prod + +* ``doctrine:mapping:import`` - allows Doctrine to introspect an existing + database and create mapping information. For more information, see + :doc:`/cookbook/doctrine/reverse_engineering`. + +* ``doctrine:mapping:info`` - tells you all of the entities that Doctrine + is aware of and whether or not there are any basic errors with the mapping. + +* ``doctrine:query:dql`` and ``doctrine:query:sql`` - allow you to execute + DQL or SQL queries directly from the command line. + +.. note:: + + To be able to load data fixtures to your database, you will need to have + the DoctrineFixturesBundle bundle installed. To learn how to do it, + read the ":doc:`/bundles/DoctrineFixturesBundle/index`" entry of the + documentation. + +.. tip:: + + This page shows working with Doctrine within a controller. You may also + want to work with Doctrine elsewhere in your application. The + :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` + method of the controller returns the ``doctrine`` service, you can work with + this in the same way elsewhere by injecting this into your own + services. See :doc:`/book/service_container` for more on creating + your own services. diff --git a/cookbook/doctrine/index.rst b/cookbook/doctrine/index.rst index 7f19ef7d4fe..a62c736db11 100644 --- a/cookbook/doctrine/index.rst +++ b/cookbook/doctrine/index.rst @@ -14,3 +14,4 @@ Doctrine resolve_target_entity mapping_model_classes registration_form + console diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index b2777f42f5e..60ec9546e85 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -62,6 +62,7 @@ * :doc:`/cookbook/doctrine/resolve_target_entity` * :doc:`/cookbook/doctrine/mapping_model_classes` * :doc:`/cookbook/doctrine/registration_form` + * :doc:`/cookbook/doctrine/console` * :doc:`/cookbook/email/index` From 2af5c607553551ca8c62cfc22d8337cedff4cdcd Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:25:14 +0100 Subject: [PATCH 008/145] Small tweaks to summary --- book/doctrine.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 8abdaaf4958..ab09847d3e7 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1369,11 +1369,12 @@ that allow you to take different actions as objects go through their persistence lifecycle. For more information about Doctrine, see the *Doctrine* section of the -:doc:`cookbook `, which includes the following articles: +:doc:`cookbook `. Some usefull articles might be: -* :doc:`/bundles/DoctrineFixturesBundle/index` * :doc:`/cookbook/doctrine/common_extensions` * :doc:`/cookbook/doctrine/console` +* :doc:`/bundles/DoctrineFixturesBundle/index` +* :doc:`/bundles/DoctrineMongoDBBundle/index` .. _`Doctrine`: http://www.doctrine-project.org/ .. _`MongoDB`: http://www.mongodb.org/ From 18cbacd46de88ec0c297e86e975bd8cf79354151 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:27:37 +0100 Subject: [PATCH 009/145] Clean up reference pointers list --- book/doctrine.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index ab09847d3e7..8fc6e72dc6e 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1382,10 +1382,8 @@ For more information about Doctrine, see the *Doctrine* section of the .. _`Query Builder`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html .. _`Doctrine Query Language`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html .. _`Association Mapping Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html -.. _`DateTime`: http://php.net/manual/en/class.datetime.php .. _`Mapping Types Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#doctrine-mapping-types -.. _`Property Mapping documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping +.. _`Property Mapping`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping .. _`Lifecycle Events documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events .. _`Reserved SQL keywords documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#quoting-reserved-words .. _`Persistent classes`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#persistent-classes -.. _`Property Mapping`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping From 034d69abd89f6274a543f3cc8a2d2f72a12c619b Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:47:05 +0100 Subject: [PATCH 010/145] Tweaked new cookbook article --- cookbook/doctrine/console.rst | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/cookbook/doctrine/console.rst b/cookbook/doctrine/console.rst index b48cd3e3f3c..0cfb7befca0 100644 --- a/cookbook/doctrine/console.rst +++ b/cookbook/doctrine/console.rst @@ -6,17 +6,17 @@ Console Commands ---------------- The Doctrine2 ORM integration offers several console commands under the -``doctrine`` namespace. To view the command list you can run the console -without any arguments: +``doctrine`` namespace. To view the command list you can use the ``list`` +command: .. code-block:: bash - $ php app/console + $ php app/console list doctrine -A list of available commands will print out, many of which start with the -``doctrine:`` prefix. You can find out more information about any of these -commands (or any Symfony command) by running the ``help`` command. For example, -to get details about the ``doctrine:database:create`` task, run: +A list of available commands will print out. You can find out more information +about any of these commands (or any Symfony command) by running the ``help`` +command. For example, to get details about the ``doctrine:database:create`` +task, run: .. code-block:: bash @@ -41,20 +41,3 @@ Some notable or interesting tasks include: * ``doctrine:query:dql`` and ``doctrine:query:sql`` - allow you to execute DQL or SQL queries directly from the command line. - -.. note:: - - To be able to load data fixtures to your database, you will need to have - the DoctrineFixturesBundle bundle installed. To learn how to do it, - read the ":doc:`/bundles/DoctrineFixturesBundle/index`" entry of the - documentation. - -.. tip:: - - This page shows working with Doctrine within a controller. You may also - want to work with Doctrine elsewhere in your application. The - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` - method of the controller returns the ``doctrine`` service, you can work with - this in the same way elsewhere by injecting this into your own - services. See :doc:`/book/service_container` for more on creating - your own services. From f7ec98ca904a92a24180bb695605739b32a45a1f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 18 Jan 2014 12:47:55 +0100 Subject: [PATCH 011/145] Added tip at a more logical place --- book/doctrine.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/book/doctrine.rst b/book/doctrine.rst index 8fc6e72dc6e..bc44ef39de9 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -517,6 +517,16 @@ of the bundle: If you're following along with this example, you'll need to create a route that points to this action to see it work. +.. tip:: + + This page shows working with Doctrine within a controller. You may also + want to work with Doctrine elsewhere in your application. The + :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` + method of the controller returns the ``doctrine`` service, you can work with + this in the same way elsewhere by injecting this into your own + services. See :doc:`/book/service_container` for more on creating + your own services. + Take a look at the previous example in more detail: * **lines 9-12** In this section, you instantiate and work with the ``$product`` From 1bf3ce0350527de5571ecc9d56440da79ee128f6 Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Mon, 6 Jan 2014 22:46:07 +0100 Subject: [PATCH 012/145] [Reference][Form Types] Add missing docs for "action" and "method" option --- reference/forms/types/form.rst | 3 +++ reference/forms/types/options/action.rst.inc | 11 +++++++++++ reference/forms/types/options/method.rst.inc | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 reference/forms/types/options/action.rst.inc create mode 100644 reference/forms/types/options/method.rst.inc diff --git a/reference/forms/types/form.rst b/reference/forms/types/form.rst index dfe67119f6c..14200097904 100644 --- a/reference/forms/types/form.rst +++ b/reference/forms/types/form.rst @@ -59,3 +59,6 @@ on all fields. .. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc +.. include:: /reference/forms/types/options/action.rst.inc + +.. include:: /reference/forms/types/options/method.rst.inc diff --git a/reference/forms/types/options/action.rst.inc b/reference/forms/types/options/action.rst.inc new file mode 100644 index 00000000000..821197ae24f --- /dev/null +++ b/reference/forms/types/options/action.rst.inc @@ -0,0 +1,11 @@ +.. versionadded:: 2.3 + The ``action`` option was introduced in Symfony 2.3. + +action +~~~~~~ + +**type**: ``string`` **default**: empty string + +This option specifies where to send the form's data on submission (usually an +URI). An empty value is considered a same-document references, i.e. the form +will be submitted to the same URI that rendered the form. diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc new file mode 100644 index 00000000000..7744367205d --- /dev/null +++ b/reference/forms/types/options/method.rst.inc @@ -0,0 +1,20 @@ +.. versionadded:: 2.3 + The ``method`` option was introduced in Symfony 2.3. + +method +~~~~~~ + +**type**: ``string`` **default**: ``POST`` + +This option specifies the HTTP method used to submit the form's data. Possible +values are: + +* POST +* GET +* PUT +* DELETE +* PATCH + +.. note:: + Using ``PUT``, ``PATCH`` and ``DELETE`` is only allowed if + :ref:`configuration-framework-http_method_override` is enabled. From 83ff4b1843f3f82369f494ffa3d17278a98b29fd Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Tue, 7 Jan 2014 07:31:18 +0100 Subject: [PATCH 013/145] Improve descriptions --- reference/forms/types/options/action.rst.inc | 3 ++- reference/forms/types/options/method.rst.inc | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/reference/forms/types/options/action.rst.inc b/reference/forms/types/options/action.rst.inc index 821197ae24f..bd1bfa10e6f 100644 --- a/reference/forms/types/options/action.rst.inc +++ b/reference/forms/types/options/action.rst.inc @@ -7,5 +7,6 @@ action **type**: ``string`` **default**: empty string This option specifies where to send the form's data on submission (usually an -URI). An empty value is considered a same-document references, i.e. the form +URI). It's value is rendered as the ``action`` attribute of the ``form`` +element. An empty value is considered a same-document reference, i.e. the form will be submitted to the same URI that rendered the form. diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index 7744367205d..27efd4840ff 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -6,8 +6,9 @@ method **type**: ``string`` **default**: ``POST`` -This option specifies the HTTP method used to submit the form's data. Possible -values are: +This option specifies the HTTP method used to submit the form's data. It's +value is rendered as the ``method`` attribute of the ``form`` element. +Possible values are: * POST * GET @@ -15,6 +16,9 @@ values are: * DELETE * PATCH +As PUT, DELETE and PATCH are not nativly supported by most clients, Symfony +simulates them, see :doc:`/cookbook/routing/method_parameters`. + .. note:: Using ``PUT``, ``PATCH`` and ``DELETE`` is only allowed if :ref:`configuration-framework-http_method_override` is enabled. From a63694532a62e4f6232b95c3d4dcfa2f6ac74b98 Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Tue, 7 Jan 2014 12:10:42 +0100 Subject: [PATCH 014/145] Fixes after review --- reference/forms/types/options/method.rst.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index 27efd4840ff..91c5a99ba2f 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -17,8 +17,10 @@ Possible values are: * PATCH As PUT, DELETE and PATCH are not nativly supported by most clients, Symfony -simulates them, see :doc:`/cookbook/routing/method_parameters`. +simulates them. For more information see +:doc:`/cookbook/routing/method_parameters`. .. note:: + Using ``PUT``, ``PATCH`` and ``DELETE`` is only allowed if :ref:`configuration-framework-http_method_override` is enabled. From cecc762018ce808e65bf2bc68764bc2c102aceeb Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Tue, 7 Jan 2014 22:27:06 +0100 Subject: [PATCH 015/145] Update "method" description --- reference/forms/types/options/method.rst.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index 91c5a99ba2f..b6df4c74374 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -7,7 +7,8 @@ method **type**: ``string`` **default**: ``POST`` This option specifies the HTTP method used to submit the form's data. It's -value is rendered as the ``method`` attribute of the ``form`` element. +value is rendered as the ``method`` attribute of the ``form`` element and to +perform some consistency checks when evaluating the form after submission. Possible values are: * POST @@ -16,11 +17,10 @@ Possible values are: * DELETE * PATCH -As PUT, DELETE and PATCH are not nativly supported by most clients, Symfony -simulates them. For more information see -:doc:`/cookbook/routing/method_parameters`. +.. note: -.. note:: - - Using ``PUT``, ``PATCH`` and ``DELETE`` is only allowed if - :ref:`configuration-framework-http_method_override` is enabled. + If not natively supported by a client, Symfony allows to simulate PUT, + DELETE and PATCH requests by using a POST request instead and passing the + intended "real" method by either using a ``X-HTTP-Method-Override`` + request header or by passing it via the special ``_method`` data field. + For more information see :doc:`/cookbook/routing/method_parameters`. From 70ca6dad2f7fec42ea6e3f80435016ad3366b616 Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Sat, 11 Jan 2014 06:55:36 +0100 Subject: [PATCH 016/145] Improvements after review --- reference/forms/types/options/action.rst.inc | 2 +- reference/forms/types/options/method.rst.inc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reference/forms/types/options/action.rst.inc b/reference/forms/types/options/action.rst.inc index bd1bfa10e6f..70977722000 100644 --- a/reference/forms/types/options/action.rst.inc +++ b/reference/forms/types/options/action.rst.inc @@ -7,6 +7,6 @@ action **type**: ``string`` **default**: empty string This option specifies where to send the form's data on submission (usually an -URI). It's value is rendered as the ``action`` attribute of the ``form`` +URI). Its value is rendered as the ``action`` attribute of the ``form`` element. An empty value is considered a same-document reference, i.e. the form will be submitted to the same URI that rendered the form. diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index b6df4c74374..00da8e316c6 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -6,10 +6,10 @@ method **type**: ``string`` **default**: ``POST`` -This option specifies the HTTP method used to submit the form's data. It's -value is rendered as the ``method`` attribute of the ``form`` element and to -perform some consistency checks when evaluating the form after submission. -Possible values are: +This option specifies the HTTP method used to submit the form's data. Its +value is rendered as the ``method`` attribute of the ``form`` element and is +used to decide whether to process the form submission in the +``handleRequest()`` method after submission. Possible values are: * POST * GET From 455549502d341d5ba01554f545be11495c00f999 Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Sat, 11 Jan 2014 07:04:46 +0100 Subject: [PATCH 017/145] Update note wording for "method" option --- reference/forms/types/options/method.rst.inc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index 00da8e316c6..fbcc7519e3e 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -19,8 +19,7 @@ used to decide whether to process the form submission in the .. note: - If not natively supported by a client, Symfony allows to simulate PUT, - DELETE and PATCH requests by using a POST request instead and passing the - intended "real" method by either using a ``X-HTTP-Method-Override`` - request header or by passing it via the special ``_method`` data field. - For more information see :doc:`/cookbook/routing/method_parameters`. + When the method is PUT, PATCH, or DELETE, Symfony will automatically + render a ``_method`` hidden field in your form. This is used to "fake" + these HTTP methods, as they're not supported on standard browsers. For + more information, see :doc:`/cookbook/routing/method_parameters`. From 793c8a046252ec815d0e39c2a984b4a93bb813df Mon Sep 17 00:00:00 2001 From: Philipp Rieber Date: Fri, 24 Jan 2014 21:31:59 +0100 Subject: [PATCH 018/145] Add note about the PATCH method --- reference/forms/types/options/method.rst.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reference/forms/types/options/method.rst.inc b/reference/forms/types/options/method.rst.inc index fbcc7519e3e..d1d6c84b1ce 100644 --- a/reference/forms/types/options/method.rst.inc +++ b/reference/forms/types/options/method.rst.inc @@ -23,3 +23,9 @@ used to decide whether to process the form submission in the render a ``_method`` hidden field in your form. This is used to "fake" these HTTP methods, as they're not supported on standard browsers. For more information, see :doc:`/cookbook/routing/method_parameters`. + +.. note: + + Only the PATCH method allows submitting partial data without that missing + fields are set to ``null`` in the underlying data (preserving default + values, if any). From c98a3da05f03dd6e382b3cc148e4f618415bc094 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:19:41 +0100 Subject: [PATCH 019/145] Adjusted doctrine service tip --- book/doctrine.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index bc44ef39de9..3eba317a2a4 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -519,13 +519,12 @@ of the bundle: .. tip:: - This page shows working with Doctrine within a controller. You may also - want to work with Doctrine elsewhere in your application. The - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` - method of the controller returns the ``doctrine`` service, you can work with - this in the same way elsewhere by injecting this into your own - services. See :doc:`/book/service_container` for more on creating - your own services. + This article shows working with Doctrine from within a controller by using + the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::getDoctrine` + method of the controller. This method is a shortcut to get the + ``doctrine`` service. You can work with Doctrine anywhere else + by injecting that service in the service. See + :doc:`/book/service_container` for more on creating your own services. Take a look at the previous example in more detail: From 7acc0d24d5cbd9e40e5b37936ddf2b4d8cc7a928 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:20:51 +0100 Subject: [PATCH 020/145] Reverted removal of getSingleResult() It's now smaller (25 to 3 lines) and uses getOneOrNullResult(). --- book/doctrine.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 3eba317a2a4..d5b17870010 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -737,7 +737,11 @@ a controller, do the following:: $products = $query->getResult(); -The ``getResult()`` method returns an array of results. +The ``getResult()`` method returns an array of results. To get only one +result, you can use ``getSingleResult()`` (which throws exception there is no +result) or ``getOneOrNullResult()``:: + + $product = $query->getOneOrNullResult(); If you're comfortable with SQL, then DQL should feel very natural. The biggest difference is that you need to think in terms of "objects" instead of rows From 91a18cdfa858f6a5e1e6e8e49ccc2cf0fd4828f1 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:26:46 +0100 Subject: [PATCH 021/145] Changed order to QueryBuilder -> DQL The QueryBuilder seems to be easier and more recommend to use. This meant the QueryBuilder section now contains the primary information and the DQL section is now reduced to somewhat a "side topic". --- book/doctrine.rst | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index d5b17870010..64e793c2c51 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -720,12 +720,42 @@ instead of querying for rows on a table (e.g. ``product``). When querying in Doctrine, you have two options: writing pure Doctrine queries or using Doctrine's Query Builder. +Querying for Objects Using Doctrine's Query Builder +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Imagine that you want to query for products, but only return products that +cost more than ``19.99``, ordered from cheapest to most expensive. You can use +Doctrine's ``QueryBuilder`` for this:: + + $repository = $this->getDoctrine() + ->getRepository('AcmeStoreBundle:Product'); + + $query = $repository->createQueryBuilder('p') + ->where('p.price > :price') + ->setParameter('price', '19.99') + ->orderBy('p.price', 'ASC') + ->getQuery(); + + $products = $query->getResult(); + +The ``QueryBuilder`` object contains every method necessary to build your +query. By calling the ``getQuery()`` method, the query builder returns a +normal ``Query`` object, which can be used to get the result of the query. + +The ``getResult()`` method returns an array of results. To get only one +result, you can use ``getSingleResult()`` (which throws exception there is no +result) or ``getOneOrNullResult()``:: + + $product = $query->getOneOrNullResult(); + +For more information on Doctrine's Query Builder, consult Doctrine's +`Query Builder`_ documentation. + Querying for Objects with DQL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Imagine that you want to query for products, but only return products that -cost more than ``19.99``, ordered from cheapest to most expensive. From inside -a controller, do the following:: +Instead of using the ``QueryBuilder``, you can alternatively write the queries +directly using DQL:: $em = $this->getDoctrine()->getManager(); $query = $em->createQuery( @@ -737,49 +767,17 @@ a controller, do the following:: $products = $query->getResult(); -The ``getResult()`` method returns an array of results. To get only one -result, you can use ``getSingleResult()`` (which throws exception there is no -result) or ``getOneOrNullResult()``:: - - $product = $query->getOneOrNullResult(); - If you're comfortable with SQL, then DQL should feel very natural. The biggest difference is that you need to think in terms of "objects" instead of rows in a database. For this reason, you select *from* the ``AcmeStoreBundle:Product`` -*object* and then alias it as ``p``. +*object* and then alias it as ``p`` (as you see, this is equal to what you +already did in the previous section). The DQL syntax is incredibly powerful, allowing you to easily join between entities (the topic of :ref:`relations ` will be covered later), group, etc. For more information, see the official Doctrine `Doctrine Query Language`_ documentation. -Using Doctrine's Query Builder -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Instead of writing the queries directly, you can alternatively use Doctrine's -``QueryBuilder`` to do the same job using a nice, object-oriented interface. -If you use an IDE, you can also take advantage of auto-completion as you -type the method names. From inside a controller:: - - $repository = $this->getDoctrine() - ->getRepository('AcmeStoreBundle:Product'); - - $query = $repository->createQueryBuilder('p') - ->where('p.price > :price') - ->setParameter('price', '19.99') - ->orderBy('p.price', 'ASC') - ->getQuery(); - - $products = $query->getResult(); - -The ``QueryBuilder`` object contains every method necessary to build your -query. By calling the ``getQuery()`` method, the query builder returns a -normal ``Query`` object, which is the same object you built directly in the -previous section. - -For more information on Doctrine's Query Builder, consult Doctrine's -`Query Builder`_ documentation. - Custom Repository Classes ~~~~~~~~~~~~~~~~~~~~~~~~~ From 8bb3195ead06f4fb8112200f8bb259612d9e47ef Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:31:51 +0100 Subject: [PATCH 022/145] Fixed spelling --- book/doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 64e793c2c51..420f45d6f6a 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -783,7 +783,7 @@ Custom Repository Classes In the previous sections, you began constructing and using more complex queries from inside a controller. In order to isolate, test and reuse these queries, -it's a good practise to create a custom repository class for your entity and +it's a good practice to create a custom repository class for your entity and add methods with your query logic there. To do this, add the name of the repository class to your mapping definition: From 20ba9e0d39190773d2c7d1b75b1bd738ca46b7b5 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:35:31 +0100 Subject: [PATCH 023/145] Readded small note about parameters --- book/doctrine.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/book/doctrine.rst b/book/doctrine.rst index 420f45d6f6a..1967b2f5d62 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -742,6 +742,12 @@ The ``QueryBuilder`` object contains every method necessary to build your query. By calling the ``getQuery()`` method, the query builder returns a normal ``Query`` object, which can be used to get the result of the query. +.. tip:: + + Take note of the ``setParameter()`` method. When working with Doctrine, + it's always a good idea to set any external values as "placeholders" + (``:price`` in the example above) as it prevents SQL injection attacks. + The ``getResult()`` method returns an array of results. To get only one result, you can use ``getSingleResult()`` (which throws exception there is no result) or ``getOneOrNullResult()``:: From 79e2216b4005e85b9c53925312f07471c1dce621 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:37:33 +0100 Subject: [PATCH 024/145] Rephrased linking paragraph for Lifecycle events --- book/doctrine.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 1967b2f5d62..aac54db9963 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1345,8 +1345,10 @@ the current date, only when the entity is first persisted (i.e. inserted): Now, right before the entity is first persisted, Doctrine will automatically call this method and the ``createdAt`` field will be set to the current date. -For more information on other lifecycle events and lifecycle callbacks in -general, see Doctrine's `Lifecycle Events documentation`_. + +There are several other lifecycle events that you can hook into. For more +information on other lifecycle events and lifecycle callbacks in general, see +Doctrine's `Lifecycle Events documentation`_. .. sidebar:: Lifecycle Callbacks and Event Listeners From 7af962c14bb940561ed73b2cb555c53410547cde Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:42:32 +0100 Subject: [PATCH 025/145] Rephrased Field Type section --- book/doctrine.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index aac54db9963..910df4e21de 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1370,8 +1370,10 @@ Doctrine Field Types Reference Doctrine comes with a large number of field types available. Each of these maps a PHP data type to a specific column type in whatever database you're -using. To see a list of all available types and more information, see -Doctrine's `Mapping Types documentation`_. +using. For each field type, the ``Column`` can be configured further, setting +the ``length``, ``nullable`` behavior, ``name`` and other options. To see a +list of all available types and more information, see Doctrine's +`Mapping Types documentation`_. Summary ------- @@ -1401,7 +1403,7 @@ For more information about Doctrine, see the *Doctrine* section of the .. _`Query Builder`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html .. _`Doctrine Query Language`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html .. _`Association Mapping Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html -.. _`Mapping Types Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#doctrine-mapping-types +.. _`Mapping Types Documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mappings .. _`Property Mapping`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping .. _`Lifecycle Events documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events .. _`Reserved SQL keywords documentation`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#quoting-reserved-words From b4dd1a107811bb65f2f16d5b1837bf33db5454b0 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 3 Feb 2014 16:43:23 +0100 Subject: [PATCH 026/145] Fixed typo + added remore section --- book/doctrine.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 910df4e21de..6cfd8d6dcd6 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1389,8 +1389,11 @@ powerful, allowing you to create complex queries and subscribe to events that allow you to take different actions as objects go through their persistence lifecycle. +Learn More +~~~~~~~~~~ + For more information about Doctrine, see the *Doctrine* section of the -:doc:`cookbook `. Some usefull articles might be: +:doc:`cookbook `. Some useful articles might be: * :doc:`/cookbook/doctrine/common_extensions` * :doc:`/cookbook/doctrine/console` From d83a8cb2fa963e068b8f98f92a538143aaa29ef1 Mon Sep 17 00:00:00 2001 From: Joshua Dickerson Date: Tue, 11 Feb 2014 13:11:39 -0500 Subject: [PATCH 027/145] Update checkbox_compound.rst.inc --- reference/forms/types/options/checkbox_compound.rst.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/options/checkbox_compound.rst.inc b/reference/forms/types/options/checkbox_compound.rst.inc index 855969d870c..df87d087e2f 100644 --- a/reference/forms/types/options/checkbox_compound.rst.inc +++ b/reference/forms/types/options/checkbox_compound.rst.inc @@ -4,5 +4,5 @@ compound **type**: ``boolean`` **default**: ``false`` This option specifies if a form is compound. As it's not the -case for checkbox, by fefault the value is overriden with +case for checkbox, by default the value is overriden with ``false`` value. From 4490dab8b135412634060eb75c96acbe2340cf50 Mon Sep 17 00:00:00 2001 From: Joshua Dickerson Date: Tue, 11 Feb 2014 13:14:15 -0500 Subject: [PATCH 028/145] Update checkbox_compound.rst.inc --- reference/forms/types/options/checkbox_compound.rst.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/options/checkbox_compound.rst.inc b/reference/forms/types/options/checkbox_compound.rst.inc index 855969d870c..7f6f47070c4 100644 --- a/reference/forms/types/options/checkbox_compound.rst.inc +++ b/reference/forms/types/options/checkbox_compound.rst.inc @@ -4,5 +4,5 @@ compound **type**: ``boolean`` **default**: ``false`` This option specifies if a form is compound. As it's not the -case for checkbox, by fefault the value is overriden with +case for checkbox, by fefault the value is overridden with ``false`` value. From 027bc973591065fd4cd05bc316adf0e3611b33db Mon Sep 17 00:00:00 2001 From: Janusz Slota Date: Wed, 12 Feb 2014 16:28:12 +0000 Subject: [PATCH 029/145] Callback: [Validator, validate] expects validate to be static Otherwise you'll get: ``` ContextErrorException: Runtime Notice: call_user_func() expects parameter 1 to be a valid callback, non-static method Vendor\Package\Validator::validate() should not be called statically in Symfony/Component/Validator/Constraints/CallbackValidator.php ``` --- reference/constraints/Callback.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/constraints/Callback.rst b/reference/constraints/Callback.rst index e370c46ecf1..36b55e97910 100644 --- a/reference/constraints/Callback.rst +++ b/reference/constraints/Callback.rst @@ -160,7 +160,7 @@ your validation function is ``Vendor\Package\Validator::validate()``:: class Validator { - public function validate($object, ExecutionContextInterface $context) + public static function validate($object, ExecutionContextInterface $context) { // ... } From 8feb85d265cd46ce936ffa9b84f1a39555222ed9 Mon Sep 17 00:00:00 2001 From: Omer Karadagli Date: Sun, 16 Feb 2014 22:05:25 +0000 Subject: [PATCH 030/145] Add missing hyphen in HTTP Fundamentals page --- book/http_fundamentals.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/http_fundamentals.rst b/book/http_fundamentals.rst index c0420ba0081..7e376257b63 100644 --- a/book/http_fundamentals.rst +++ b/book/http_fundamentals.rst @@ -538,7 +538,7 @@ regardless of how your project is developed. To name a few: * `Security`_ - A powerful library for handling all types of security inside an application; -* `Translation`_ A framework for translating strings in your application. +* `Translation`_ - A framework for translating strings in your application. Each and every one of these components is decoupled and can be used in *any* PHP project, regardless of whether or not you use the Symfony2 framework. From 3670cbb807e0716857b4679717eda90b922139f1 Mon Sep 17 00:00:00 2001 From: Omer Karadagli Date: Mon, 17 Feb 2014 23:14:29 +0000 Subject: [PATCH 031/145] Use consistent method chaining in BlogBundle sample application - Moved semicolon to end of last chained method - Moved getManager() to next line to avoid having multiple chained methods in the same line --- book/from_flat_php_to_symfony2.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index e65f75436b9..02c456d3e15 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -550,7 +550,8 @@ them for you. Here's the same sample application, now built in Symfony2:: { public function listAction() { - $posts = $this->get('doctrine')->getManager() + $posts = $this->get('doctrine') + ->getManager() ->createQuery('SELECT p FROM AcmeBlogBundle:Post p') ->execute(); @@ -565,8 +566,7 @@ them for you. Here's the same sample application, now built in Symfony2:: $post = $this->get('doctrine') ->getManager() ->getRepository('AcmeBlogBundle:Post') - ->find($id) - ; + ->find($id); if (!$post) { // cause the 404 page not found to be displayed From d2b57be9ea9fe619591ca082c3f4d2b70a087c8e Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 17:25:30 +0100 Subject: [PATCH 032/145] Documented missing FormType variables --- reference/forms/twig_reference.rst | 102 +++++++++++++++++------------ 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/reference/forms/twig_reference.rst b/reference/forms/twig_reference.rst index e33b6b5f1c0..0da054b1c85 100644 --- a/reference/forms/twig_reference.rst +++ b/reference/forms/twig_reference.rst @@ -295,47 +295,65 @@ object: get('name')->vars['label'] ?> -+-----------------+-----------------------------------------------------------------------------------------+ -| Variable | Usage | -+=================+=========================================================================================+ -| ``id`` | The ``id`` HTML attribute to be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``name`` | The name of the field (e.g. ``title``) - but not the ``name`` | -| | HTML attribute, which is ``full_name`` | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``full_name`` | The ``name`` HTML attribute to be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``errors`` | An array of any errors attached to *this* specific field (e.g. ``form.title.errors``). | -| | Note that you can't use ``form.errors`` to determine if a form is valid, | -| | since this only returns "global" errors: some individual fields may have errors | -| | Instead, use the ``valid`` option | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``valid`` | Returns ``true`` or ``false`` depending on whether the whole form is valid | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``value`` | The value that will be used when rendering (commonly the ``value`` HTML attribute) | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``read_only`` | If ``true``, ``readonly="readonly"`` is added to the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``disabled`` | If ``true``, ``disabled="disabled"`` is added to the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``required`` | If ``true``, a ``required`` attribute is added to the field to activate HTML5 | -| | validation. Additionally, a ``required`` class is added to the label. | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``max_length`` | Adds a ``maxlength`` HTML attribute to the element | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``pattern`` | Adds a ``pattern`` HTML attribute to the element | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``label`` | The string label that will be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``multipart`` | If ``true``, ``form_enctype`` will render ``enctype="multipart/form-data"``. | -| | This only applies to the root form element. | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``attr`` | A key-value array that will be rendered as HTML attributes on the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``label_attr`` | A key-value array that will be rendered as HTML attributes on the label | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``compound`` | Whether or not a field is actually a holder for a group of children fields | -| | (for example, a ``choice`` field, which is actually a group of checkboxes | -+-----------------+-----------------------------------------------------------------------------------------+ +.. versionadded:: 2.3 + The ``method`` and ``action`` variables were introduced in Symfony 2.3. + ++------------------------+-------------------------------------------------------------------------------------+ +| Variable | Usage | ++========================+=====================================================================================+ +| ``form`` | The current FormView instance | ++------------------------+-------------------------------------------------------------------------------------+ +| ``id`` | The ``id`` HTML attribute to be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``name`` | The name of the field (e.g. ``title``) - but not the ``name`` | +| | HTML attribute, which is ``full_name`` | ++------------------------+-------------------------------------------------------------------------------------+ +| ``full_name`` | The ``name`` HTML attribute to be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``errors`` | An array of any errors attached to *this* specific field | +| | (e.g. ``form.title.errors``). | +| | Note that you can't use ``form.errors`` to determine if a form is valid, | +| | since this only returns "global" errors: some individual fields may have errors | +| | Instead, use the ``valid`` option | ++------------------------+-------------------------------------------------------------------------------------+ +| ``valid`` | Returns ``true`` or ``false`` depending on whether the whole form is valid | ++------------------------+-------------------------------------------------------------------------------------+ +| ``value`` | The value that will be used when rendering (commonly the ``value`` HTML attribute) | ++------------------------+-------------------------------------------------------------------------------------+ +| ``read_only`` | If ``true``, ``readonly="readonly"`` is added to the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``disabled`` | If ``true``, ``disabled="disabled"`` is added to the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``required`` | If ``true``, a ``required`` attribute is added to the field to activate HTML5 | +| | validation. Additionally, a ``required`` class is added to the label. | ++------------------------+-------------------------------------------------------------------------------------+ +| ``max_length`` | Adds a ``maxlength`` HTML attribute to the element | ++------------------------+-------------------------------------------------------------------------------------+ +| ``pattern`` | Adds a ``pattern`` HTML attribute to the element | ++------------------------+-------------------------------------------------------------------------------------+ +| ``label`` | The string label that will be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``multipart`` | If ``true``, ``form_enctype`` will render ``enctype="multipart/form-data"``. | +| | This only applies to the root form element. | ++------------------------+-------------------------------------------------------------------------------------+ +| ``attr`` | A key-value array that will be rendered as HTML attributes on the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``label_attr`` | A key-value array that will be rendered as HTML attributes on the label | ++------------------------+-------------------------------------------------------------------------------------+ +| ``compound`` | Whether or not a field is actually a holder for a group of children fields | +| | (for example, a ``choice`` field, which is actually a group of checkboxes | ++------------------------+-------------------------------------------------------------------------------------+ +| ``block_prefixes`` | An array of all the names of the parent types | ++------------------------+-------------------------------------------------------------------------------------+ +| ``translation_domain`` | The domain of the translations for this form | ++------------------------+-------------------------------------------------------------------------------------+ +| ``cache_key`` | An unique key which is used for caching | ++------------------------+-------------------------------------------------------------------------------------+ +| ``data`` | The normalized data of the type | ++------------------------+-------------------------------------------------------------------------------------+ +| ``method`` | The method of the current form (POST, GET, etc) | ++------------------------+-------------------------------------------------------------------------------------+ +| ``action`` | The action of the current form (POST, GET, etc) | ++------------------------+-------------------------------------------------------------------------------------+ .. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig From 98e828fcd14ce8c0bd5c68e8b7a9472ef7612e47 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 17:29:49 +0100 Subject: [PATCH 033/145] Documented checked variable --- reference/forms/types/checkbox.rst | 7 +++++++ reference/forms/types/radio.rst | 7 +++++++ reference/forms/types/variables/checked.rst.inc | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 reference/forms/types/variables/checked.rst.inc diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index e39c393dae7..24af9aabfa0 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -13,6 +13,8 @@ if the box is unchecked, the value will be set to false. +-------------+------------------------------------------------------------------------+ | Options | - `value`_ | +-------------+------------------------------------------------------------------------+ +| Variables | - `checked`_ | ++-------------+------------------------------------------------------------------------+ | Overridden | - `empty_data`_ | | options | - `compound`_ | +-------------+------------------------------------------------------------------------+ @@ -46,6 +48,11 @@ Field Options .. include:: /reference/forms/types/options/value.rst.inc +Variables +--------- + +.. include:: /reference/forms/types/variables/checked.rst.inc + Overridden options ------------------ diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index 0cf937db3bb..4a246088312 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -15,6 +15,8 @@ If you want to have a Boolean field, use :doc:`checkbox Date: Tue, 18 Feb 2014 18:47:00 +0100 Subject: [PATCH 034/145] Documented choice variables --- reference/forms/types/checkbox.rst | 14 ++++++++----- reference/forms/types/choice.rst | 20 +++++++++++++++++++ reference/forms/types/radio.rst | 14 ++++++++----- .../forms/types/variables/checked.rst.inc | 6 ------ 4 files changed, 38 insertions(+), 16 deletions(-) delete mode 100644 reference/forms/types/variables/checked.rst.inc diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index 24af9aabfa0..7d41b2e46ee 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -48,11 +48,6 @@ Field Options .. include:: /reference/forms/types/options/value.rst.inc -Variables ---------- - -.. include:: /reference/forms/types/variables/checked.rst.inc - Overridden options ------------------ @@ -82,3 +77,12 @@ These options inherit from the :doc:`form ` type: .. include:: /reference/forms/types/options/error_mapping.rst.inc .. include:: /reference/forms/types/options/mapped.rst.inc + +Form Variables +-------------- + +======== ============ ============================================ +Variable Type Usage +======== ============ ============================================ +checked ``Boolean`` Whether or not the current input is checked. +======== ============ ============================================ diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index c60b2f29f55..5836d203efb 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -156,3 +156,23 @@ These options inherit from the :doc:`form ` type: .. include:: /reference/forms/types/options/inherit_data.rst.inc .. include:: /reference/forms/types/options/by_reference.rst.inc + +Field Variables +--------------- + +====================== ============ =========================================================== +Variable Type Usage +====================== ============ =========================================================== +multiple ``Boolean`` The value of the `multiple`_ option +expanded ``Boolean`` The value of the `expanded`_ option +preferred_choices ``array`` A nested array containing the ``ChoiceView`` objects of + choices which should be presented to the user with priority +choices ``array`` A nested array containing the ``ChoiceView`` objects of + the remaining choices +separator ``string`` The seperator to use between choice groups +empty_value ``mixed`` The empty value if not already in the list, otherwise + ``null`` +is_selected ``callable`` A callable which takes a ``ChoiceView`` and the value + and returns if the choice is selected or not +empty_value_in_choices ``Boolean`` Whether the empty value is in the choice list +====================== ============ =========================================================== diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index 4a246088312..56dacaf7893 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -34,11 +34,6 @@ If you want to have a Boolean field, use :doc:`checkbox ` type: .. include:: /reference/forms/types/options/error_mapping.rst.inc .. include:: /reference/forms/types/options/mapped.rst.inc + +Form Variables +-------------- + +======== ============ ============================================ +Variable Type Usage +======== ============ ============================================ +checked ``Boolean`` Whether or not the current input is checked. +======== ============ ============================================ diff --git a/reference/forms/types/variables/checked.rst.inc b/reference/forms/types/variables/checked.rst.inc deleted file mode 100644 index ed55f85803c..00000000000 --- a/reference/forms/types/variables/checked.rst.inc +++ /dev/null @@ -1,6 +0,0 @@ -checked -~~~~~~~ - -**type**: boolean - -Whether or not the current input is checked. From 7d10315c548435f5bb849c562338471fe89e2149 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 20:02:39 +0100 Subject: [PATCH 035/145] Documented selectedchoice test --- reference/forms/twig_reference.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/forms/twig_reference.rst b/reference/forms/twig_reference.rst index 0da054b1c85..a9ceddfaeff 100644 --- a/reference/forms/twig_reference.rst +++ b/reference/forms/twig_reference.rst @@ -192,6 +192,24 @@ good idea to include this in your form tag:
+Form Tests Reference +-------------------- + +Tests can be executed by using the ``is`` operator in Twig to create a +condition. Read `the Twig documentation`_ for more information. + +.. _form-twig-selectedchoice: + +selectedchoice(selected_value) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This test will check if the current choice is equal to the ``selected_value`` +or if the current choice is in the array (when ``selected_value`` is an array). + +.. code-block:: jinja + +