symfony - 嵌入式表单 - 多个复选框 [英] symfony - embeddedForm - multiple checkboxes

查看:31
本文介绍了symfony - 嵌入式表单 - 多个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文章管理模块和标签模块标签只是每个行项目的单个标签

I have article admin module and a tag module Tags are simply a single tag per row item

我想做的是将所有标签的列表(作为复选框)嵌入到我的文章模块中

What I'd like to do is to embed the list of all the tags (as checkboxes) into my article module

我可以用嵌入的表单来做到这一点吗?

Could I do this with embedded forms?

这是我的架构:

article:
  id:                                      ~
  title:                                   { type: VARCHAR, size: '255', required: true }
  tags:                                    { type: VARCHAR, size: '500' }
  created_at:                              { type: TIMESTAMP, required: true }
  updated_at:                              { type: TIMESTAMP, required: true }

tag:
  id:                                      ~
  tag:                                     { type: VARCHAR, size: '500', required: true } 
  ord_id:                                  { type: INTEGER,  required: true }
  created_at:                              ~
  updated_at:                              ~

item_tag:
  id:                                      ~
  item_id:                                 { type: INTEGER, required: true, foreignTable: item, foreignReference: id, onDelete: cascade }
  tag_id:                                  { type: INTEGER, required: true, foreignTable: tag, foreignReference: id, onDelete: restrict }
  created_at:                              ~

item:
  id:                                      ~
  article_id:                              { type: INTEGER, foreignTable: article, foreignReference: id, onDelete: cascade }

所以当我需要显示标签并更新上面的表格时

So when I need the tags to be displayed and will update the above tables

推荐答案

如果您在模型中正确定义了文章和标签之间的关系,那么生成的表单应该包含标签选择小部件.

If you have defined the relationship between the article and tags correctly in your model, then the generated Forms should contain tag select widgets.

在表单文档中搜索sfWidgetFormChoice"以获取更多信息:http://www.symfony-project.org/jobeet/1_4/Doctrine/zh/10

Search "sfWidgetFormChoice" in the Forms documentation for more information: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10

注意:示例是使用 Doctrine ORM 创建的,但在 Propel 中一切都应该以相同的方式工作.

Note: The examples are created using the Doctrine ORM but everything should work the same way with Propel as well.

这篇关于symfony - 嵌入式表单 - 多个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆