Reputation: 121
I would like to bind a parameter to my doctrine request using the setParams
function . Following is my code, please correct me if you see any mistakes.
$input = $request->getParameter('query');
$result = Doctrine_Query::create()
->from('jobeetCategory')
->where("name LIKE '$:name'")
->setParams(['name'=>$input])
->fetchArray();
Upvotes: 1
Views: 428
Reputation: 2007
You don't need to try to use setParams()
:
$result = Doctrine_Query::create()
->from('jobeetCategory')
->where('name LIKE ?', $input)
->fetchArray()
;
From the Sf1.4 docs:
->where('j.expires_at > ?', date('Y-m-d H:i:s', time()));`
BTW i see by the 'jobeet' that you are following the symfony 1.4 beginner tutorial.If you are beginner to symfony 1.4 and are not forced to use it you should definitely learn Symfony 2/3 instead, symfony 1.4 is no longer supported by sensiolabs and the community is pretty dead.(and Symfony 2/3 is awesome)
EDIT:
If you have more conditions just use andWhere()
or 'orWhere()' as much as you need
$result = Doctrine_Query::create()
->from('jobeetCategory')
->where('name LIKE ?', $input['name'])
->andWhere('price < ?', $input['price'])
->orWhere('shipping > ?', $input['shipping'])
->fetchArray()
;
For further reference: http://doctrine.readthedocs.io/en/latest/en/manual/dql-doctrine-query-language.html#where-clause
Upvotes: 2