Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a word in doctrine ORM?

I would like to know if this is possible in doctrine ORM symfony. I have a list of Products. Each product has a Title. let say their titles are:

1. Great Mango
2. Show Mango
3. King Mango

I use this doctrine to find the title

$repository->findByTitle("Mango");

but I display nothing. If I complete the title to search it like "King Mango". It display but not the list with the MANGO word.

I used this link for reference. but if you have more documentation about this. I'm happy to learn from it.

like image 998
user3818576 Avatar asked Oct 25 '25 14:10

user3818576


1 Answers

To use a like in the where clause, you have to use where condition with setParameter. query as below:

$title = 'Mango';
$query = $repository->createQueryBuilder('a')
           ->where('a.title LIKE :title')
           ->setParameter('title', '%'.$title.'%')
           ->getQuery();
like image 193
mith Avatar answered Oct 28 '25 03:10

mith