From 14b44466e8e9c0bccb38cd082287d147d410219e Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Mon, 21 Sep 2015 13:22:02 +0900 Subject: [PATCH] =?UTF-8?q?[6-17]=20findAllByKeyword()=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/lists/ch06/06-17.txt | 19 +++++++++++++++++++ src/AppBundle/Entity/InquiryRepository.php | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 docs/lists/ch06/06-17.txt diff --git a/docs/lists/ch06/06-17.txt b/docs/lists/ch06/06-17.txt new file mode 100644 index 0000000..8f04af4 --- /dev/null +++ b/docs/lists/ch06/06-17.txt @@ -0,0 +1,19 @@ +use Doctrine\Common\Collections\ArrayCollection; +... +class InquiryRepository extends \Doctrine\ORM\EntityRepository +{ + public function findAllByKeyword($keyword) + { + $query = $this->createQueryBuilder('i') + ->where('i.name LIKE :keyword') + ->orWhere('i.tel LIKE :keyword') + ->orWhere('i.email LIKE :keyword') + ->orderBy('i.id', 'DESC') + ->setParameters([ + ':keyword' =>'%'.$keyword.'%' + ]) + ->getQuery(); + + return new ArrayCollection($query->getResult()); + } +} diff --git a/src/AppBundle/Entity/InquiryRepository.php b/src/AppBundle/Entity/InquiryRepository.php index e0f33e9..d44d13b 100644 --- a/src/AppBundle/Entity/InquiryRepository.php +++ b/src/AppBundle/Entity/InquiryRepository.php @@ -2,6 +2,8 @@ namespace AppBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; + /** * InquiryRepository * @@ -10,4 +12,18 @@ */ class InquiryRepository extends \Doctrine\ORM\EntityRepository { + public function findAllByKeyword($keyword) + { + $query = $this->createQueryBuilder('i') + ->where('i.name LIKE :keyword') + ->orWhere('i.tel LIKE :keyword') + ->orWhere('i.email LIKE :keyword') + ->orderBy('i.id', 'DESC') + ->setParameters([ + ':keyword' =>'%'.$keyword.'%' + ]) + ->getQuery(); + + return new ArrayCollection($query->getResult()); + } }