Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony1 symfony 1.4中不存在m-n关系的筛选器_Symfony1_Symfony 1.4_Symfony Forms - Fatal编程技术网

Symfony1 symfony 1.4中不存在m-n关系的筛选器

Symfony1 symfony 1.4中不存在m-n关系的筛选器,symfony1,symfony-1.4,symfony-forms,Symfony1,Symfony 1.4,Symfony Forms,我在symfony 1.4中有一个多对多关系。我正在使用条令管理生成器,并希望在该字段的标准sfWidgetFormDoctrineChoice中添加一个“Is Empty”复选框,以执行“WHERE NOT EXISTS”查询并查找未标记的条目。有人看到解决办法了吗 谢谢大家! 小部件: class ynWidgetFormDoctrineChoiceEmpty extends sfWidgetFormDoctrineChoice { protected function configur

我在symfony 1.4中有一个多对多关系。我正在使用条令管理生成器,并希望在该字段的标准
sfWidgetFormDoctrineChoice
中添加一个“Is Empty”复选框,以执行“WHERE NOT EXISTS”查询并查找未标记的条目。有人看到解决办法了吗

谢谢大家!

小部件:

class ynWidgetFormDoctrineChoiceEmpty extends sfWidgetFormDoctrineChoice
{
  protected function configure( $options = array(), $attributes = array() )
  {
    parent::configure( $options, $attributes );

    $this->addOption( 'with_empty', false );
    $this->addOption( 'empty_label', 'none' );
    $this->addOption( 'template', '%select%<div>%empty_checkbox% %empty_label%</div>' );
  }

  public function render( $name, $value = null, $attributes = array(), $errors = array() )
  {
    $select = parent::render( $name, $value, $attributes, $errors );

    if ( $this->getOption('with_empty') ) {
      $values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array());

      return strtr($this->getOption('template'), array(
        '%select%'         => $select,
        '%empty_checkbox%' => $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')),
        '%empty_label%'    => $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))),
      ));
    }
    else {
      return $select;
    }
  }
}
FooFormFilter
中:

public function addBarListColumnQuery( Doctrine_Query $query, $field, $values )
{
  if (!is_array($values))
  {
    $values = array($values);
  }

  if (!count($values))
  {
    return;
  }

  if (
    isset( $values['is_empty'] )
    && $values['is_empty'] == 'on'
  ) {
    $query
      ->andWhere('NOT EXISTS (SELECT fb.bar_id '
        . 'FROM FooBar fb where ' . $query->getRootAlias()
        . '.id=fb.foo_id)');
  }
  else {
    $query
      ->leftJoin($query->getRootAlias().'.FooBar FooBar')
      ->andWhereIn('FooBar.bar_id', $values)
    ;
  }
}
public function addBarListColumnQuery( Doctrine_Query $query, $field, $values )
{
  if (!is_array($values))
  {
    $values = array($values);
  }

  if (!count($values))
  {
    return;
  }

  if (
    isset( $values['is_empty'] )
    && $values['is_empty'] == 'on'
  ) {
    $query
      ->andWhere('NOT EXISTS (SELECT fb.bar_id '
        . 'FROM FooBar fb where ' . $query->getRootAlias()
        . '.id=fb.foo_id)');
  }
  else {
    $query
      ->leftJoin($query->getRootAlias().'.FooBar FooBar')
      ->andWhereIn('FooBar.bar_id', $values)
    ;
  }
}