0

我在 Symfony 1.4 中的过滤器有问题(由管理员生成器创建的模块)

 <?php

abstract class BaseTestFormFilter extends BaseFormFilterDoctrine
{
    public function setup()
    {
        $this->setWidgets(array(
            'country' => new sfWidgetFormChoice(array('choices' => $this->getChoicesByField('country'))),
            'currency' => new sfWidgetFormChoice(array('choices' => $this->getChoicesByField('currency'))),
        ));

        $this->setValidators(array(
            'country' => new sfValidatorPass(array('required' => false)),
            'currency' => new sfValidatorPass(array('required' => false)),
        ));

        $this->widgetSchema->setNameFormat('economicCalendar_filters[%s]');

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

        $this->setupInheritance();

        parent::setup();
    }

    private function getChoicesByField($field){
        $q = Doctrine_Query::create()
            ->select("t.$field")
            ->from('Test t')
            ->groupBy("$field")
            ->execute();

        $query_result = $q->toArray();
        $result = array();
        foreach ($query_result as $val) {
            $result[$val[$field]] = $val[$field];
        }
        return $result;
    }

    public function getModelName()
    {
        return 'Test';
    }

    public function getFields()
    {
        return array(
            'country' => 'Text',
            'currency' => 'Text',
        );
    }
}

所以我有 2 个看起来像选择的过滤器字段。问题是它们正在填充,当我尝试过滤但不过滤任何内容时,数据是相同的,就像没有它们一样。将感谢任何帮助。

4

1 回答 1

0

所以问题 - 我需要添加方法

public function addCountryColumnQuery($query, $field, $value)
{
    if (!empty($value))
    {
        $query->andWhereIn('country', $value);
    }
}

如果没有这种方法,获取过滤值的查询不会得到我需要的值。

于 2013-10-07T09:53:31.377 回答