doutang3077 2013-07-03 13:40
浏览 122

解决方案如何在Yii Active Record中将数据保存/更新为少数表(模型)

I am new in Yii and Active Record and I want to ask you some solution how to do some things. I have 3 tables in db: car - info about cars, car_model - info about models of the cars, car__car_model - relation table, which binds this 2 tables in Many_to_Many relation - it has fileds - id_car,id_model,is_hidden,orderby.

Task is to show some (till 5) similar car models on car page.

i have a big form in which i enter information about car (car table), and i have 5 html blocks (5 rows in db in table car_model)with some input fields. Each block it is a row in car_model table - it contain fields: id_model - (primary key in car_model table), and some info fields which in this car_model table. Records in car_model table are always already exist, user just choose model_id in form and update this row and by checkbox he can do this relation hidden (is_hidden field) In other words, user just updates car_model table records and binds them to car table (car__car_model table). My question is following: how can i implement it, using activeFields and correct using Active Record ideology. Have any ideas?

I set up relation with this tables - and display this data with no problem - saving/updating data i implement using static content (Chtml) - set up static names for this html fields and in Controller i foreach this fields - but i think it is not correct

Image of this form: http://programmer.pp.ua/out/1.png

Tables:

car: id,other fields

car_model: id,other text fields which need to update

car__car_model:id_car,id_model,is_hidden(checkbox in form),orderby**

Relations in Car Model:

'carAdviceModel'=> array(self::HAS_MANY,'CarCarModel', 'id_car'),
'adviceModels'  => array(self::HAS_MANY, 'CarModel', 'id_model', 'through' => 'carAdviceModel'),

Thanks you in advance Sorry for my bad English - it is my first question here.

  • 写回答

1条回答 默认 最新

  • doushun9875 2013-07-04 04:25
    关注

    Ok, this is a bit odd, but maybe you want to send three models to the view, each an array of 5 models. The models can be brand new, or some can start out populated. Search the Yii definitive guide for 'Collecting Tabular Input'. It will give you everything you need to know about how to do this. You can validate all the models. You can also save all the models without having to validate them all again by using save(false).

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退