简体   繁体   English

在 Symfony 中使用 Doctrine 的搜索系统

[英]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?这应该如何在 Symfony 1.4 中完成?

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 %?%"也许您还想将 %% 添加到您的 like 查询->where("a.title LIKE %?%"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM