I have 2 database let say DB A and DB B, here is the recap: DB A has:
- tbl_a
- tbl_b
- tbl_c
- tbl_d
DB B has:
- tbl_x
- tbl_y
tbl_d has:
tbl_a.id, tbl_b.id, tbl_c.id, tbl_x.id, tbl_y.name
I want add data into tbl_d using cascade dropdown list
I already success in making dropdown list to get list of tbl_a.id, tbl_b.id, tbl_c.id
with tbl_a.id
as parent but still can't get data for tbl_x.id
and tbl_y.name
.
I get complicacy when try retriving list of tbl_x.id because:
- the database was different but still in 1 server and using same username and password
- tbl_x only has relation with tbl_a which tbl_x.description = tbl_a.name
here is my add function in 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'));
}
here is some of my view
<?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')); ?>
Can anyone give me idea how I should do it?