【问题标题】:How to create multiple recordsets for each selected checkbox如何为每个选中的复选框创建多个记录集
【发布时间】:2012-01-20 12:29:47
【问题描述】:

我有以下架构,我想使用 Symfony 1.4 和 Doctrine 创建一个表单,用户可以从选择框中选择杂志,然后单击多个复选框,其中每个复选框都是一个问题。

在伪标记中应该是这样的:

[选择]杂志[/选择]

[复选框]问题 1[复选框]

[复选框]问题 2[复选框]

[复选框]问题 3[复选框]

[复选框]问题 4[复选框]

[复选框]问题 5[复选框]

如果表单被保存,它应该为每个选中的复选框创建一个记录集。广告 ID 通过 url 传递给表单。

我尝试了几种方法来实现这一点,但我坚持了几个星期,希望这里有人可以帮助我。

在实际项目中,我需要收集 25 个所描述的表单,但如果我只是让这个基本表单正常工作,这将不是问题。

我应该创建一个广告表格并将规划表格嵌入其中吗?我总是用 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 

【问题讨论】:

    标签: forms symfony1 doctrine symfony-1.4


    【解决方案1】:

    如果我理解正确(让我检查一下:您想在某些杂志的某些问题上展示广告?)那么这个怎么样?

    使用从 Planing 对象到 Issue 对象的关系,一对多,然后使用 Symfony 博客中所述的内置 sfWidgetFormChoice:http://symfony.com/blog/new-in-symfony-1-2-make-your-choice(向下滚动到“Group your Choices”)。

    因此,不要使用 sfWidgetFormDoctrineChoice,而是使用其父级并编写自己的方法来构建按杂志分组的问题数组,并存储在嵌套数组中。您可以像这样覆盖 PlaningForm 配置中的小部件:

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

    然后将方法添加到IssueTable.class.php,该方法返回一个嵌套数组,其中包含问题 ID 和标题,按杂志标题分组,应如下所示:

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

    【讨论】:

    • 我应该补充一点,这看起来不太像您要求的(更改复选框的选择),但您可以在页面加载后使用 javascript 添加该行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2018-08-23
    • 1970-01-01
    相关资源
    最近更新 更多