public function executeSearch(sfWebRequest $request)
{
$q = Doctrine_Core::getTable('News')
->createQuery('a')
->where("a.title LIKE ?", array($request->getParameter('text')))
if ($request->getParameter('sub')){
->andWhere('a.subtile = 2');
}
$test = $q->execute();
}
为什么这不起作用?我有一个解析错误。如何在Symfony 1.4中完成这项工作?
答案 0 :(得分:2)
public function executeSearch(sfWebRequest $request)
{
$q = Doctrine_Core::getTable('News')
->createQuery('a')
->where("a.title LIKE ?", array($request->getParameter('text')));
if ($request->getParameter('sub')){
$test->andWhere('a.subtile = 2');
}
$test = $q->execute();
}
将是正确的语法
也许您还想将%%添加到您的查询->where("a.title LIKE %?%"