我怎么能让两个表格输入相关的cakephp

时间:2016-05-15 06:05:04

标签: cakephp cakephp-2.0

我想在add.ctp中创建这个。 当用户选择部门时,在文件表单字段中,仅显示与他们选择的部门相同的文件

我的add.ctp

中的

            <div class="form-group">
                <?php echo $this->Form->input('department', array('class' => 'form-control', 'placeholder' => 'Department', 'options' => array( 
                    'Administrator' => 'Administrator',
                    'Multimedia' => 'Multimedia', 
                    'Treasurer' => 'Treasurer',
                    'Marketing' => 'Marketing',
                ), 
                    'empty' => '(Choose Department)',));?>
            </div>
            <div class="form-group">
                <?php echo $this->Form->input('fail_id', array('class' => 'form-control', 'label' => 'File','placeholder' => 'File Id', 'empty' => '(Choose File)'));?>
            </div>

在我的控制器中

public function add() {
    if ($this->request->is('post')) {
        $this->Borrow->create();
            $this->request->data['Borrow']['user_id']= $this->Auth->user('id');
        if ($this->Borrow->save($this->request->data)) {
            $this->Session->setFlash(__('The borrow has been saved.'), 'default', array('class' => 'alert alert-success'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The borrow could not be saved. Please, try again.'), 'default', array('class' => 'alert alert-danger'));
        }
    }
    $users = $this->Borrow->User->find('list');
    $fails = $this->Borrow->Fail->find('list');
    $fails = $this->Borrow->Fail->find('list');
    $this->set(compact('users', 'fails', 'fails'));
}

感谢善意帮助。

1 个答案:

答案 0 :(得分:0)

你必须使用ajax帖子。用户选择部门后,你应该发送一个值为department的ajax帖子并获取相关文件并更新第二个组合框。