开发者

Multi-select foreign key filter

开发者 https://www.devze.com 2023-03-07 12:24 出处:网络
I\'m trying to set up a multi-select filter on a foreign key in the symfony admin.I think I\'ve set up everything correctly but for some reason it\'s not working:

I'm trying to set up a multi-select filter on a foreign key in the symfony admin. I think I've set up everything correctly but for some reason it's not working:

public function configure()
{
    parent::configure();

    $s = Doctrine_Query::create()->
      from('Status s')->
      execute();

    $status_choices = array();
    foreach ($s as $key => $value) {
        $status_choices[$value->getId()] = $value->getName();
    }

    $this->widgetSchema['status_id'] = new sfWidgetFormChoice(array('choices' => $status_choices, 'multiple' => true, 'expanded' => true));

    $this->validatorSchema['status_id'] = new sfValidatorChoice(array('required' => false, 'choices' => $status_choices, 'multiple' => true));



}

public function getFields()
{

    $fields = parent::getFields();
    $fields['status_id'] = 'StatusId';
    return开发者_开发技巧 $fields;

}

public function addStatusIdQuery(Doctrine_Query $query, $field, $values)
{
    $fieldName = $this->getFieldName($field);

  if (!empty($values))
  {
        $query->addWhereIn(sprintf('%s.%s', $query->getRootAlias(), $fieldName), $values);
  }
}

Any help would be greatly appreciated...


In your validatorSchema, to validate data posted, you have to use array_keys($status_choices) because values sent after posting the form are keys and not labels.

And the addWhereIn is not a Doctrine_Query method, use andWhereIn or whereIn

Hope that will help you

0

精彩评论

暂无评论...
验证码 换一张
取 消