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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)