Symfony1 多选外键过滤器
我正在尝试在symfony admin中的外键上设置多选筛选器。我认为我已正确设置了所有内容,但由于某些原因,它不起作用:Symfony1 多选外键过滤器,symfony1,filter,admin,generator,Symfony1,Filter,Admin,Generator,我正在尝试在symfony admin中的外键上设置多选筛选器。我认为我已正确设置了所有内容,但由于某些原因,它不起作用: public function configure() { parent::configure(); $s = Doctrine_Query::create()-> from('Status s')-> execute(); $status_choices = array(); foreach ($s
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);
}
}
非常感谢您的帮助…在您的validatorSchema中,要验证发布的数据,您必须使用数组键($status\u选项) 因为在发布表单后发送的值是键而不是标签 并且addwhere不是一种查询方法,请使用andwhere或其中 希望这对你有帮助