CakePHP 2.x从列表中删除项目

时间:2015-02-26 05:46:26

标签: list cakephp items

所以我的应用程序有学生用户。他们每个人都有一个帐户,可以上传文件。在我看来,我有2个字段:下拉菜单字段和浏览文件。这两个字段下面是一个表,列出了该用户上传的所有文件。

我的下拉菜单包含需要上传的文件类型列表(例如申请表,记录转录本,生物数据等)。用户必须从列表中选择一个并上传文件。

所以我想要做的是,一旦上传了一个文件类型,让我们说应用程序表单,它将从下拉列表中删除。当然,如果他们上传了错误的文件,在表格内有一个删除按钮。单击删除将使所选文件的上载类型返回到下拉列表。

如何做到这一点?

查看:

$this->Form->input('type', array(
    'class' => 'form-control',
    'options' => array(
        'Application Form' => 'Application Form',
        'Manual' => 'Manual',
        'Picture' => 'Picture'
    ),
    'empty' => 'Choose an upload type'
));
$this->Form->input('file.', array(
    'class' => 'form-control',
    'type' => 'file'
));

下拉列表和文件浏览:

<?php
    foreach ($docs as $docs){
        <?php echo $docs['Upload']['type'] ?>
        <?php echo $this-Html-link('Remove from Table', array('controller' => 'schools', 'action' => 'remove')); ?>
    }

控制器:

public function documents(){
    $this-> layout = 'schools';
    $this->set('docs', $this-Upload->find('all', array('condition' => array('Upload.iddocs' => $doc['Doc']['id']))));
    if($this->request->is('post')){
        $file = $this-request->data;
        $size = (sizeof($this->request->data['Upload']['file']));
        $is = $this->Auth->User('userId');
        $school = $this->School->find('first', array('conditions' => array('usersId' => $id)));
        if(!is_dir(ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name']))
            mkdr(ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name']);
                for($i=0; $i<$size; $i++){
                    $dest_file = ROOT . DS . 'app' . DS . 'uploads' . DS . $school['School']['name'] . DS . $file['Upload']['file'][$i]['name'];
                    if(move_uploaded_file($file['Upload']['file'][$i]['name']['tmp_name'], $dest_file)){
                        $this->Upload->create();
                        $data = array(
                            'iddocs' => $doc['Doc']['id'],
                            'dest' => $dest_file,
                            'type' => $this->request->data['Upload']['type']
                        );
                        $this->Upload->save($data);
                    }
                }
    }
}

&GT;

0 个答案:

没有答案