【问题标题】:instruction IF in Doctrine query in Symfony?Symfony中Doctrine查询中的指令IF?
【发布时间】:2011-07-03 16:03:15
【问题描述】:

我怎样才能做点什么:

  public function executeSearch(sfWebRequest $request)
  {
    $test = 1;

    $this->shows = Doctrine_Core::getTable('Show')
      ->createQuery('a')
      ->where('a.name = ?', 'Tom')
   if ($test == 1) {   ->andWhere('a.last_name = ?', 'Jerry') }
      ->execute();
  }

这不起作用。如果在教义查询中,我该如何指导?

或者:

  public function executeSearch(sfWebRequest $request)
  { 
    if(isset($test)){
    $test = 'Jerry';
    }
  //now if isset $test then andWhere search only with Jerry, if not isset andWhere search ALL

    $this->shows = Doctrine_Core::getTable('Show')
      ->createQuery('a')
      ->where('a.name = ?', 'Tom')
      ->andWhere('a.last_name = ?', $test) }
      ->execute();
  }

【问题讨论】:

    标签: php sql symfony1 doctrine symfony-1.4


    【解决方案1】:
    $q = Doctrine_Core::getTable('Show')
      ->createQuery('a')
      ->where('a.name = ?', 'Tom');
    
    if ($test == 1) 
    {   
      $q->andWhere('a.last_name = ?', 'Jerry');
    }
    
    $this->shows = $q->execute();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多