问题描述
我在旧的 cakePHP 1.2 上被困了几个月我不明白这个框架的逻辑,我完全迷失了......
我有一个表格可以从我的表格中添加/删除,称为合同(见下文) 如您所见,我希望能够为每个表单添加 1 个区域。我设法在这里创建了一个带有自己区域的表演表。
array(
'files' => '','Contract' => array(
'name' => '','beggin' => '','end' => '','content1' => '<p><br></p>','content2' => '<p><br></p>','content3' => '','content4' => '','content5' => '','content7' => '','content8' => ''
),'Zone' => array(
(int) 0 => array(
'zone_name' => 'Bat A','id_prestation' => array(
(int) 0 => '10',(int) 1 => '11'
)
),(int) 1 => array(
'zone_name' => 'Bat B',(int) 1 => '12',(int) 2 => '13',(int) 3 => '14'
)
)
)
)
到目前为止,我没有任何困难。 表 Contract 和 Prestation 之间的关系是 $hasAndBelongsToMany 这是我的表格:
我的问题是提交表单时,数据没有保存。 有人可以解释一下我做错了什么并解释我应该做什么吗? 以下是我的所有代码,您可能需要了解我要解释的内容:
<?PHP
class Contract extends AppModel {
public $hasMany = array('Document','Statu');
public $hasAndBelongsToMany = array('Prestation');
public $belongsTo = array('Client','Residence'); public function contracts() {
return $this->find(
'all',array(
'conditions' => array(
'Contract.is_active' => false
)
)
);
}
}
public function add() { if ($this->request->is(array('post','put')))
{
// Todo: Rewrite or remove the two next conditions when client and residences will be re-implemented.
// SUPPRESSION DU CLIENT
if (!empty($this->request->data['Contract']['client_id'])) {
unset($this->request->data['Client']);
} else {
unset($this->request->data['Contract']['client_id']);
} // SUPPRESSION DE LA RESIDENCE
if (!empty($this->request->data['Contract']['residence_id'])) {
unset($this->request->data['Residence']);
} else {
unset($this->request->data['Contract']['residence_id']);
} // AJOUT DU STATUS
// AJOUT DES PRESTATIONS
if (!empty($this->request->data['Zone'])) {
foreach ($this->request->data['Zone'] as $key => $zone) {
$this->request->data['Zone'][$key] = $zone;
}
}
$this->request->data['Statu'] = array( 0 => array( 'status' => 'proposed' ) ); // AJOUT DU CONTRAT
$this->Contract->create(); $this->request->data['Contract']['is_active'] = false;
if ($this->Contract->saveAll($this->request->data))
{
$this->Session->setFlash(__('Contrat enregistré.'));
return $this->redirect(array('controller' => 'contracts','action' => 'index'));
} $this->Session->setFlash(__("Impossible d'enregistrer le devis."));
}
else
{
$this->set( 'clients',$this->Client->find('list') );
$this->set( 'residences',$this->Residence->find('list') );
$this->set( 'prestations',$this->Prestation->find('list') );
}
}
感谢您的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)