cakephp字段命名约定-保存多个模型
我正在尝试允许用户将图表与多个系列一起保存cakephp字段命名约定-保存多个模型,cakephp,Cakephp,我正在尝试允许用户将图表与多个系列一起保存 我应该如何命名输入字段以及调用什么保存方法来保存所有模型?一次保存多个关联模型值的常规惯例如下: Chart hasMany Series Series belongsTo Chart Series hasAndBelongsToMany Industry Series hasAndBelongsToMany Sector Industry hasMany Sector Sector belongsTo Industry 注意:不要忘记分配模型之间的
我应该如何命名输入字段以及调用什么保存方法来保存所有模型?一次保存多个关联模型值的常规惯例如下:
Chart hasMany Series
Series belongsTo Chart
Series hasAndBelongsToMany Industry
Series hasAndBelongsToMany Sector
Industry hasMany Sector
Sector belongsTo Industry
注意:不要忘记分配模型之间的关系
但您可以通过在视图页面中正确定义字段值来实现它。请记住遵循以下模式:
$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);
更清楚地说。就你而言:
对于Usermodel数据字段:
topMdel["topModelFieldName"];
topModel["FirstAssociateModel"]["FirstAssociateModelFieldName"];
topModel["FirstAssociateModel"]["SecondAssociateModel"]["SecondAssociateModelFieldName"];
User["user_name"];
User["user_email"]; //etc.
User["Chart"]["chart_name"];
User["Chart"]["chart_value"]; //etc.
对于图表模型数据字段:
topMdel["topModelFieldName"];
topModel["FirstAssociateModel"]["FirstAssociateModelFieldName"];
topModel["FirstAssociateModel"]["SecondAssociateModel"]["SecondAssociateModelFieldName"];
User["user_name"];
User["user_email"]; //etc.
User["Chart"]["chart_name"];
User["Chart"]["chart_value"]; //etc.
希望有帮助。
对于系列模型数据字段:
topMdel["topModelFieldName"];
topModel["FirstAssociateModel"]["FirstAssociateModelFieldName"];
topModel["FirstAssociateModel"]["SecondAssociateModel"]["SecondAssociateModelFieldName"];
User["user_name"];
User["user_email"]; //etc.
User["Chart"]["chart_name"];
User["Chart"]["chart_value"]; //etc.