Fantic Onger
Fantic Onger

Reputation: 93

Search system with Doctrine in Symfony

  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();
  }

Why don't this work? I have a parse error. How should this be done in Symfony 1.4?

Upvotes: 0

Views: 756

Answers (1)

Flask
Flask

Reputation: 4996

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();
}

would be the correct syntax

maybe you also want to add %% to your like query ->where("a.title LIKE %?%"

Upvotes: 2

Related Questions