从cakephp中的多个数据库填充级联下拉列表

时间:2015-03-04 10:14:04

标签: php mysql cakephp cascadingdropdown

我有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.idtbl_y.name的数据。

尝试重新审阅tbl_x.id列表时会出现问题,因为:

  1. 数据库不同但仍在1台服务器中并使用相同的用户名和密码
  2. tbl_x只与tbl_a有关,其中tbl_x.description = tbl_a.name
  3. 这是我在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')); ?>
    

    任何人都可以告诉我应该怎么做吗?

0 个答案:

没有答案