私は一日中、数字に基づいて同じフォームに複数の挿入を試みていましたが、どこにも行けませんでした。ここの誰かが私を助けてくれることを願っています...
1.4教義でアドミンジェネレーターを使用しています。2 つのフィールドのみで生成したフォームがあります。やろうとしているのは、挿入された数値に基づいて、フォームが x 回繰り返されることです。
ジェネレーター ファイルで、フォームの先頭にテキスト フィールドを配置するパーシャルを追加しました。デフォルト値は 1 です。2 を選択すると、以下のフォームが 2 回複製されます。
これが私のフォームに対して行ったことです..実際に
class prizesActions extends autoPrizesActions
{ public function executeNew(sfWebRequest $request) {
$this->form = $this->configuration->getForm(null, array('n' => 5));
$this->prizes = $this->form->getObject();
} }
PrizesForm には、次のように記述しました。
class PrizesForm extends BasePrizesForm
{ public function configure() { $array = $this->getOptions(); for ($i = 0; $i < $array['n']; $i++) {
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'prize_no' => new sfWidgetFormInputText(),
'prize' => new sfWidgetFormInputText(),
'created_at' => new sfWidgetFormDateTime(),
'updated_at' => new sfWidgetFormDateTime(),
));
$this->setValidators(array(
'id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)),
'prize_no' => new sfValidatorInteger(array('required' => false)),
'prize' => new sfValidatorString(array('max_length' => 200, 'required' => false)),
'created_at' => new sfValidatorDateTime(),
'updated_at' => new sfValidatorDateTime(),
));
$this->widgetSchema->setNameFormat('prizes['.$i.'][%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
}
unset( $this['updated_at'],
$this['created_at']
);
} }
ループは機能していると思いますが、すべてのエントリでウィジェットを上書きしているため、代わりに追加する他の方法が見つかりません。何か案は?
ありがとう、