2つの外部キーを持つテーブルTableModuleがあります。たとえば、 fk1とfk2です。
fk1は表1のpk1に移動します
fk2は表2のpk2に移動します
モジュールを作成しました。たとえば、 TableModule(fkを持つもの)を使用するModuleとしましょう。
それらのfk用に4つのフィルターを作成したいと思います:2つの入力テキストと2つのドロップダウン。特に、 fkごとに2つのフィルターを作成したいと思います。これは:
For fk1 I would get:
-InputText
-Dropdown (choice in propel)
For fk2 I would get:
-InputText
-Dropdown (choice in propel)
もちろん、これは表1と表2の結果を示します。
今、私のconfig.ymlで私は得ました:
...
filter:
display: [fk1, fk1TextFilter, fk2, fk2TextFilter]
...
これは次のとおりです。fk1とfk2はドロップダウンとしてフィルタリングされます。部分 的なfk1TextFilterとfk2TextFilterは、テキスト入力を使用してフィルタリングするようにカスタマイズする必要があります。
なぜそれらのパーシャルを作成したのですか?config.ymlでfkを複製できないためです!!
私がやったこと(表1lib/filter/table1/ModuleFormFilter
にあることに注意してください):
public function configure()
{
$this->setWidgets(array(
'fk1' => new sfWidgetFormPropelChoice(array('model' => 'table1', 'add_empty' => true,)),
'fk1TextFilter' => new sfWidgetFormInput(),
'fk2' => new sfWidgetFormPropelChoice(array('model' => 'table2', 'add_empty' => true,)),
'fk2TextFilter' => new sfWidgetFormInput(),
));
$this->setValidators(array(
'fk1TextFilter' => new sfValidatorPropelChoice(array('model' => 'table1', 'column' => 'id', 'required' => false)),
'fk1' => new sfValidatorPropelChoice(array('model' => 'table1', 'column' => 'id', 'required' => false)),
'fk2TextFilter' => new sfValidatorPropelChoice(array('model' => 'table2', 'column' => 'id', 'required' => false)),
'fk2' => new sfValidatorPropelChoice(array('model' => 'table2', 'column' => 'id', 'required' => false)),
));
$this->validatorSchema->setPostValidator(
new sfValidatorPropelUnique(array('model' => 'table2', 'column' => array('fk2')))
);
$this->widgetSchema->setNameFormat('model[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
}
これは次のとおりです。前述のように、2つのtextInputと2つのドロップダウンを作成しました。
-inputtextまたはdropdowns-を使用する場合、fkだけで問題なく動作します。問題は、fkを複製できないことです。できません:
$this->setWidgets(array(
'fk1' => new sfWidgetFormPropelChoice(array('model' => 'table1', 'add_empty' => true,)),
'fk1' => new sfWidgetFormInput(),
'fk2' => new sfWidgetFormPropelChoice(array('model' => 'table2', 'add_empty' => true,)),
'fk2' => new sfWidgetFormInput(),
));
ページを実行すると、次のようになります。
You must define a "filterByfk1TextFilter" method in the ModelQuery class to be able to filter with the "fk1TextFilter" field.
いくつかのリンク(1、2)が見つかりましたが、機能していません。symfonyのドキュメントには具体的な例はありません。
何をどのように作成する必要がありますか?
今では、同じようにlib/filter/table1/ModuleFormFilter
:
public function getFields()
{
$fields = parent::getFields();
$fields['fk1TextFilter'] = 'fk1TextFilter';
$fields['fk2TextFilter'] = 'fk2TextFilter';
return $fields;
}
public function addModelfk1TextFilterQuery($query, $field, $value)
{
//add your filter query!
//for example in your case
$rootAlias = $query->getRootAlias();
$query = ModelQuery::create()
->filterByfk1TextFilter()
->find();
//remember to return the $query!
return $query;
}
私のために働いていません。私を手伝ってくれますか??