Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit485b529

Browse files
committed
Removed duplicated DQL documentation
The doctrine docs already has a big great documentation on this. There isno reason to duplicate it in the sf docs. This commit removes everythingexcept a simple example.It also moves the sentence about the return result above, since that makesmore sense now the getSingleResult example is removed.
1 parent42c80d1 commit485b529

File tree

1 file changed

+4
-51
lines changed

1 file changed

+4
-51
lines changed

‎book/doctrine.rst

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -728,65 +728,18 @@ a controller, do the following::
728728

729729
$products = $query->getResult();
730730

731+
The ``getResult()`` method returns an array of results.
732+
731733
If you're comfortable with SQL, then DQL should feel very natural. The biggest
732734
difference is that you need to think in terms of "objects" instead of rows
733-
in a database. For this reason, you select *from* ``AcmeStoreBundle:Product``
734-
and then alias it as ``p``.
735-
736-
The ``getResult()`` method returns an array of results. If you're querying
737-
for just one object, you can use the ``getSingleResult()`` method instead::
738-
739-
$product = $query->getSingleResult();
740-
741-
..caution::
742-
743-
The ``getSingleResult()`` method throws a ``Doctrine\ORM\NoResultException``
744-
exception if no results are returned and a ``Doctrine\ORM\NonUniqueResultException``
745-
if *more* than one result is returned. If you use this method, you may
746-
need to wrap it in a try-catch block and ensure that only one result is
747-
returned (if you're querying on something that could feasibly return
748-
more than one result)::
749-
750-
$query = $em->createQuery('SELECT ...')
751-
->setMaxResults(1);
752-
753-
try {
754-
$product = $query->getSingleResult();
755-
} catch (\Doctrine\Orm\NoResultException $e) {
756-
$product = null;
757-
}
758-
// ...
735+
in a database. For this reason, you select *from* the ``AcmeStoreBundle:Product``
736+
*object* and then alias it as ``p``.
759737

760738
The DQL syntax is incredibly powerful, allowing you to easily join between
761739
entities (the topic of:ref:`relations<book-doctrine-relations>` will be
762740
covered later), group, etc. For more information, see the official Doctrine
763741
`Doctrine Query Language`_ documentation.
764742

765-
..sidebar::Setting Parameters
766-
767-
Take note of the ``setParameter()`` method. When working with Doctrine,
768-
it's always a good idea to set any external values as "placeholders",
769-
which was done in the above query:
770-
771-
..code-block::text
772-
773-
... WHERE p.price > :price ...
774-
775-
You can then set the value of the ``price`` placeholder by calling the
776-
``setParameter()`` method::
777-
778-
->setParameter('price', '19.99')
779-
780-
Using parameters instead of placing values directly in the query string
781-
is done to prevent SQL injection attacks and should *always* be done.
782-
If you're using multiple parameters, you can set their values at once
783-
using the ``setParameters()`` method::
784-
785-
->setParameters(array(
786-
'price' => '19.99',
787-
'name' => 'Foo',
788-
))
789-
790743
Using Doctrine's Query Builder
791744
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
792745

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp