CakePHP如何传递外键

时间:2016-03-24 17:44:03

标签: cakephp cakephp-2.0

我有2个表:table bien和table disponibilite。我想检索表Bien的id并将其自动放入表disponibilite但它不起作用。 这是我的代码

public function add($id = null ) {
    $this->loadModel("Bien");
    $biens = $this->Disponibilitebien->Bien->find('list', array('conditions'=>array('Bien.idBien'=>$id)));
     $this-> set('biens',$biens);
    if ($this->request->is('post')) {
        $this->Disponibilitebien->create();
        if ($this->Disponibilitebien->save($this->request->data)) {
            $this->Flash->success(__('The disponibilitebien has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Flash->error(__('The disponibilitebien could not be saved. Please, try again.'));
        }
    }

}

这是表格: enter image description here

1 个答案:

答案 0 :(得分:0)

id等于

cycle-snabbdom

$biens['Bien']['id'];