【问题标题】:Search system with Doctrine in SymfonySymfony 中的 Doctrine 搜索系统
【发布时间】:2011-08-17 19:59:26
【问题描述】:
  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 中应该如何做到这一点?

【问题讨论】:

  • 如果您使用 MySQL,请注意 ->where("a.title LIKE %?%") 它不会在标题列上使用可能的索引! MySQL 仅支持右手小丑(标题 LIKE ?%)。

标签: php symfony1 doctrine


【解决方案1】:
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 %?%"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    相关资源
    最近更新 更多