我有2个数据库,比如DB A和DB B,这里是回顾: DB A有:
- tbl_a
- tbl_b
- tbl_c
- tbl_d
DB B有:
- tbl_x
- tbl_y
tbl_d有:
tbl_a.id, tbl_b.id, tbl_c.id, tbl_x.id, tbl_y.name
我想使用级联下拉列表将数据添加到tbl_d中
我已成功制作下拉列表,以tbl_a.id, tbl_b.id, tbl_c.id
列出tbl_a.id
作为父级,但仍无法获取tbl_x.id
和tbl_y.name
的数据。
尝试重新审阅tbl_x.id列表时会出现问题,因为:
这是我在Controller中的添加功能:
public function add() {
if ($this->request->is('post')) {
$this->D->create();
Controller::loadModel('C');
$data = $this->C->find('first', array(
'conditions' => array(
'C.id' => $this->request->data['D']['c_id']
)
));
$this->request->data['D']['c_name'] = $data['C']['name'];
$this->loadModel('X','Y');
$x = $this->X->find('list',array(
'conditions' => array(
'X.x_number' => $this->request->data['D']['x_no']
)
));
$this->set('X',$x);
$y = $this->Y->find('list', array(
'conditions' => array(
'Y.code' => $this->request->data['D']['y_code']
)
));
$this->set('Y',$y);
if ($this->D->save($this->request->data)) {
$this->Session->setFlash(__('The data has been saved.'), 'success');
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The data could not be saved. Please, try again.'));
}
}
$a = $this->D->A->find('list');
$types = array(
'prepaid' => 'Prepaid',
'postpaid' => 'Postpaid',
'hybrid' => 'Hybrid'
);
$this->set(compact('a', 'types'));
}
这是我的一些观点
<?php echo $this->Form->create('D'); ?>
<?php
echo $this->Form->input('a_id', array('empty' => '-- Select --', 'default' => '-- Select --'));
echo $this->Form->input('b_id', array('empty' => '-- Select --'));
echo $this->Form->input('c_id', array('empty' => '-- Select --'));
echo $this->Form->input('x_no', array('options' => $x,
'class' => 'span5'));
echo $this->Form->input('y');
echo $this->Form->input('type');
?>
<?php echo $this->Form->end(__('Submit')); ?>
任何人都可以告诉我应该怎么做吗?