[英]CakePHP : Saving Multiple Checkbox Associated Data
我一直在搜索其他教程和指南,但没有发现任何正在做的事情。
我有一个具有多个选择字段的窗体,该窗体返回一个数组。 我想将此数组(Locationattribute)插入引用相关字段和位置的另一个模型中。 这是我遇到问题的地方。 我从下面的表单中获取数组,但是在发现的所有示例中,我都需要在每个数据条目中同时包含field和location_id,因为我不知道有多少
Array
(
[Location] => Array
(
[name] =>
[type] =>
[specialities] =>
[phone] =>
[address_num] =>
[address_street] =>
[address_suffix] =>
[address_state] =>
[address_suburb] =>
[address_postcode] =>
[num_docs] =>
[additional_services] =>
[funds] =>
[created_by] => 1
[assigned_to] => 1
)
[Hour] => Array
(
[mon_active] => 0
[mon_open] => 10:00
[mon_close] => 10:00
[tues_active] => 0
[tues_open] => 10:00
[tues_close] => 10:00
[wed_active] => 0
[wed_open] => 10:00
[wed_close] => 10:00
[thurs_active] => 0
[thurs_open] => 10:00
[thurs_close] => 10:00
[fri_active] => 0
[fri_open] => 10:00
[fri_close] => 10:00
[sat_active] => 0
[sat_open] => 10:00
[sat_close] => 10:00
[sun_active] => 0
[sun_open] => 10:00
[sun_close] => 10:00
)
[Locationattibute] => Array
(
[1] => Array
(
[field] => patient_type
[created_by] => 1
[assigned_to] => 1
[data] => Array
(
[0] => Individuals
[1] => Families
[2] => Children
[3] => Elderly
)
)
)
)
有没有办法以提供的格式保存此数据,如果没有,我该如何将阵列格式化为可接受的格式。 我考虑过只在控制器中手动构建它,但是我尝试遵循最佳实践。
请注意,我是从位置模型调用此保存请求的
供参考,这是我的关系
位置
class Location extends AppModel {
public $hasMany = array('Contact', 'Response', 'LocationAttribute');
public $hasOne = array('Hour');
public $belongsTo = array('User' => array(
'className' => 'User',
'foreignKey' => 'assigned_to',
'dependent' => false
));
位置属性
class Locationattribute extends AppModel {
public $belongsTo = array('Location' => array(
'className' => 'Location',
'foreignKey' => 'location_id',
'dependent' => false
));
在Location模型中,您在$hasMany
声明中使用LocationAttribute
,但是在模型和数据中,您具有Locationattribute
。 您确定这不是造成问题的原因吗?
我很想知道Locationattribute
模型表的结构是什么样子。 您是要为4个数据数组元素中的每一个保存一行,还是要分别对应表中的一个字段?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.