使用cakephp将复选框保存到单独的表
我有一些空间用来存放可能会产生费用的事件和项目 在后端,我想添加一个空间和可能的费用,这样我就有了一个表单,其中有多个选择这些费用的复选框 我希望它将事件空间ID写入facility_event_spaces_ID列,并将费用写入我的“event_charges”表中的facility_event_charges_ID列 它没有把任何东西保存到我的桌子上,活动费用。 我可能有一些不正确的模型或控制器或两者。任何cakephp大师都有建议吗 我们正在运行CakePHP1.3。谢谢使用cakephp将复选框保存到单独的表,php,cakephp,checkbox,has-and-belongs-to-many,Php,Cakephp,Checkbox,Has And Belongs To Many,我有一些空间用来存放可能会产生费用的事件和项目 在后端,我想添加一个空间和可能的费用,这样我就有了一个表单,其中有多个选择这些费用的复选框 我希望它将事件空间ID写入facility_event_spaces_ID列,并将费用写入我的“event_charges”表中的facility_event_charges_ID列 它没有把任何东西保存到我的桌子上,活动费用。 我可能有一些不正确的模型或控制器或两者。任何cakephp大师都有建议吗 我们正在运行CakePHP1.3。谢谢 此外,这是
此外,这是设施费用表
我发现将数据保存到单独表格的一种方法是:
$maxId = $this->FacilityEventSpace->getMaxId();
// routines for Charges
$charges = $this->data['FacilityEventSpace']['charge'];
$n = 0;
foreach ($charges as $key => $cost) {
$charge = array('EventCharge'=>array(
'id'=>'',
'facility_event_spaces_id'=>$maxId[0][0]['max(id)'],
'facility_event_charges_id'=>$cost
)
);
$this->EventCharge->save($charge['EventCharge']);
$n = $n + 1;
} // end charges
我发现将数据保存到单独表的一种方法是:
$maxId = $this->FacilityEventSpace->getMaxId();
// routines for Charges
$charges = $this->data['FacilityEventSpace']['charge'];
$n = 0;
foreach ($charges as $key => $cost) {
$charge = array('EventCharge'=>array(
'id'=>'',
'facility_event_spaces_id'=>$maxId[0][0]['max(id)'],
'facility_event_charges_id'=>$cost
)
);
$this->EventCharge->save($charge['EventCharge']);
$n = $n + 1;
} // end charges
由于我的复选框来自一个单独的表,“设施\事件\费用”和那些“选中”的将保存到另一个表,“事件\费用”如何在我的edit.ctp文件中呈现,所有复选框包括那些选中的复选框?因为我的复选框来自一个单独的表,“设施\事件\费用”和那些被选中的“选中”保存到另一个表,“事件费用”如何在我的edit.ctp文件中呈现所有复选框,包括选中的复选框?
<?php
class FacilityEventSpace extends AppModel {
var $name = 'FacilityEventSpace';
var $hasAndBelongstoMany = array('FacilityEventCharge' =>
array('className' => 'FacilityEventCharge',
'joinTable' => 'event_charges',
'foreignKey' => 'facility_event_spaces_id',
'associationForeignKey' => 'facility_event_charges_id',
'with' =>'EventCharge'
),
);
} // end Model
?>
<?php
class FacilityEventCharge extends AppModel {
var $name = 'FacilityEventCharge';
} // end Model
?>
<?php
class EventCharge extends AppModel
{
var $name = 'EventCharge';
} // end Model
?>
$this->set('charges', $this->FacilityEventCharge->find('list', array('fields' => array('id', 'type')) ));
if (!empty($this->data)) {
if($this->FacilityEventSpace->save($this->data))
{
$this->flash('The event space has been saved.','/FacilityEventSpaces/');
return;
}
}
$maxId = $this->FacilityEventSpace->getMaxId();
// routines for Charges
$charges = $this->data['FacilityEventSpace']['charge'];
$n = 0;
foreach ($charges as $key => $cost) {
$charge = array('EventCharge'=>array(
'id'=>'',
'facility_event_spaces_id'=>$maxId[0][0]['max(id)'],
'facility_event_charges_id'=>$cost
)
);
$this->EventCharge->save($charge['EventCharge']);
$n = $n + 1;
} // end charges