Skip to content

Commit

Permalink
[6-17] findAllByKeyword()メソッドを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenorigoto committed Dec 28, 2015
1 parent ad2ed73 commit 14b4446
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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());
}
}
16 changes: 16 additions & 0 deletions src/AppBundle/Entity/InquiryRepository.php
Expand Up @@ -2,6 +2,8 @@

namespace AppBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

/**
* InquiryRepository
*
Expand All @@ -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());
}
}

0 comments on commit 14b4446

Please sign in to comment.