Symfony 1.4过滤器不起作用

时间:2013-10-07 08:18:21

标签: php symfony-1.4

我的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',
        );
    }
}

所以我有两个看起来像选择的过滤字段。问题是它们正在填充,当我尝试过滤时,但不过滤任何东西,数据是相同的,就像它们一样。是否会给予任何帮助。

1 个答案:

答案 0 :(得分:0)

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

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

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