2012-01-20 10 views
1

私は以下のスキーマを持っており、ユーザーが選択ボックスからマガジンを選択して各チェックボックスが1つの場合はSymfony 1.4とDoctrineでフォームを作成したい問題。疑似マークアップで選択したチェックボックスごとに複数のレコードセットを作成する方法

それは次のようになります。

[選択]マガジン[/選択]

[チェックボックス]問題1 [チェックボックス]

[チェックボックス]問題2 [チェックボックス]

[チェックボックス]問題3 [チェックボックス]

[チェックボックス]問題4 [チェックボックス]

[チェックボックス]問題5 [チェックボックス]

フォームが保存されている場合、選択された各チェックボックスごとに1つのレコードセットが作成されます。広告IDは、URLを介してフォームに渡されます。

私はこれを達成するためにいくつかの方法を試しましたが、私は数週間これに留まり、ここに誰かが私を助けてくれることを願っています。

実際のプロジェクトでは、記述されたフォームのうち25個のコレクションが必要ですが、この基本フォームのみを動作させると問題はありません。

私はAdvertisementフォームを作成し、それにPlingフォームを埋め込むべきですか?私はいつもPlaningフォームで直接試してみました。

ご意見、ご了承ください。 そして私の貧しい私の英語を申し訳ありません。

Advertisement: 
    columns: 
    title:     { type: string(100), notnull: true } 

Issue: 
    columns: 
    magazine_id:   { type: integer, notnull: true } 
    number:     { type: string(10), notnull: true } 
    relations: 
    Magazine: 
     local: magazine_id 
     foreign: id 
     foreignAlias: Issues 
     type: one 
     foreignType: many 

Magazine: 
    columns: 
    title:     { type: string(100) } 

Planing: 
    columns: 
    advertisement_id:   { type: integer, notnull: true } 
    magazine_id:    { type: integer, notnull: true } 
    issue_id:     { type: integer, notnull: true } 
    relations: 
    Issue: 
     local: issue_id 
     foreign: id 
     foreignAlias: Planings 
     type: one 
     foreignType: many 
    Advertisement: 
     local: advertisement_id 
     foreign: id 
     foreignAlias: Planings 
     type: one 
     foreignType: many 
    Magazine: 
     local: magazine_id 
     foreign: id 
     foreignAlias: Planings 
     type: one 
     foreignType: many 

答えて

1

私が正しく理解していれば(私はチェックしてみましょう:あなたは、特定の雑誌の特定の問題に広告を表示したい?)その方法については、このですか?

PlaningオブジェクトからIssueオブジェクトへのリレーションを1対多に使用し、symfonyのブログ「http://symfony.com/blog/new-in-symfony-1-2-make-your-choice」に記載されているように組み込みのsfWidgetFormChoiceを使用します(「選択肢をグループ化」までスクロールします)。

したがって、sfWidgetFormDoctrineChoiceを使用する代わりに、その親を使用して、ネストされた配列に格納された雑誌でグループ化された問題の配列を作成する独自のメソッドを記述します。あなたはこのようなあなたのPlaningForm設定でウィジェットを上書きすることができます。

$this->widgetSchema['issues_list'] = new sfWidgetFormChoice(array(
    'multiple' => true, 
    'expanded' => true, 
    'choices' => Doctrine_Core::getTable('Issue')->getIssuesForSelect(), 
)); 

次にようになるはずです雑誌のタイトルでグループ化されたタイトルを、との問題IDのネストされた配列を返すことIssueTable.class.phpにメソッドを追加:

array(
    'Magazine 1' => array(
    17 => 'Issue 1', 
    18 => 'Issue 2', 
    28 => 'Issue 3', 
), 
    'Magazine 2' => array(
    11 => 'Issue 26', 
    19 => 'Issue 27', 
    29 => 'Issue 28', 
), 
); 
+0

これは、あなたが尋ねたもの(チェックボックスを変更する選択)と全く同じようには見えませんが、ページが読み込まれるとjavascriptでその動作を追加できるということを付け加えておきます。 – inanimatt

関連する問題