通常惯例,一次保存多个相关模型值是如下:
$data = array(
'User' => array('userFieldName' => 'fieldValue'),
'Chart' => array(
array(
'chartFieldName' => "chartFieldValue",
'Series' => array(
array(
'firstSerieItemField' => "Value",
),
array(
'secondSerieItemField' => "Value",
)
...
...//More Series Data
)
)
)
);
$this->User->saveAll($data);
注:不要忘记分配
模型之间的关系,但你可以在查看页面中正确定义字段值来实现它。请记住遵循以下模式:
topMdel["topModelFieldName"];
topModel["FirstAssociateModel"]["FirstAssociateModelFieldName"];
topModel["FirstAssociateModel"]["SecondAssociateModel"]["SecondAssociateModelFieldName"];
要更清楚。你的情况:
有关的usermodel数据字段:
User["user_name"];
User["user_email"]; //etc.
有关图表模型数据字段:
User["Chart"]["chart_name"];
User["Chart"]["chart_value"]; //etc.
希望帮助。 适用系列型号数据区:
User["Chart"]["Series"][0]["series_1_name"];
User["Chart"]["Series"][1]["series_2_name"];
User["Chart"]["Series"][2]["series_2_name"];