Yii Framework Forum: 一对多时如何一次性写入多? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

一对多时如何一次性写入多? 只要给出思路就行了,谢谢 Rate Topic: -----

#1 User is offline   eclanp 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 05-July 09

Posted 15 November 2012 - 04:12 AM

例如一个问题,有四个答案选项。问题和答案是一对多的关系,那么在新建这个问题的时候,如何一次性写入答案呢?

不是controller,而是视图的Form中应该要怎么写?
0

#2 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 586
  • Joined: 27-December 10
  • Location:china

Posted 15 November 2012 - 09:34 PM

一个视图多个models 的问题 wiki中已有多个文章介绍了 搜索下吧
How to use single form to collect data for two or more models
:lol:

How to use a single form to collect data for two or more models
0

#3 User is offline   eclanp 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 05-July 09

Posted 19 November 2012 - 01:02 AM

虽然不是我想要的,但仍然感谢你的回答。
其实我这个问题可以理解为 同一Model,一次性写入多条记录 时,表单应该怎么去写?
因为表段中的字段名是 Model_Attribute 这样生成的,所有同一个Model的情况下,字段名就会重复(包括ID)。

目前我的解决方法是从 AnserModel 继承出多个Model。不知道有没有更好的解决办法。
0

#4 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 586
  • Joined: 27-December 10
  • Location:china

Posted 19 November 2012 - 10:25 AM

收集表格块数据 示例是update 其实insert实现原理类似

官方好像有扩展 可以动态用js添加一行那种 电商程序会用到那种? :D
0

#5 User is offline   eclanp 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 05-July 09

Posted 20 November 2012 - 07:35 AM

非常感谢,搜了一下,确实有个这方面的扩展 multimodelform

不过我按照 Collecting Tabular Input 一文搞定了,原来可以这么方便,哈哈,真心感谢了!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users