如何在CAKEPHP中对多个记录执行CRUD操作

时间:2015-07-19 09:18:06

标签: cakephp

我的任务是将文件上传到文件夹及其详细信息到数据库工作正常如果我在表单中有一条记录但是如果我有多行然后它真正给出错误我搜索了很多链接但是找不到答案。

使用全部保存,保存很多,所有功能但仍然无法执行。

如果有人可以,请提供完整的代码。

我的控制器

public function add() 
{
    if ($this->request->is('post')) 
    {
        $this->File->create();
        if(empty($this->data['File']['url']['name']))
        {
            unset($this->request->data['url']['file']);
        }
        if(!empty($this->data['File']['url']['name']))
        {
            $file=$this->data['File']['url'];
            $file['name']=$this->sanitize($file['name']);
            $this->request->data['File']['url'] = time().$file['name'];

            if($this->File->save($this->request->data))
            {
                move_uploaded_file($file['tmp_name'], APP . 'outsidefiles' .DS. time().$file['name']); 
                return $this->redirect(array('action' => 'index')); 
                $this->Session->setFlash(__('Your File has been saved.'));
                //return $this->redirect(array('action' => 'index'));
            }
        }
        $this->Session->setFlash(__('Unable to add your File.'));
    }
}

.ctp文件

<h1>Add File</h1>
<?php
echo $this->Form->create('File',array('enctype'=>'multipart/form-data'));

 echo $this->Form->input('category', array(
            'options' => array( 'passport' => 'Passport', 'pancard' => 'Pancard', 'driving license' => 'Driving License', 'others' => 'Others')
        ));

        echo $this->Form->input('type', array(
            'options' => array( 'image' => 'Image', 'office' => 'Office', 'technical' => 'Technical', 'others' => 'Others')
        ));

  echo $this->Form->input('reference');

echo $this->Form->input('url', array('type' => 'file'));


 echo $this->Form->input('category', array(
            'options' => array( 'passport' => 'Passport', 'pancard' => 'Pancard', 'driving license' => 'Driving License', 'others' => 'Others')
        ));

        echo $this->Form->input('type', array(
            'options' => array( 'image' => 'Image', 'office' => 'Office', 'technical' => 'Technical', 'others' => 'Others')
        ));

  echo $this->Form->input('reference');

echo $this->Form->input('url', array('type' => 'file'));


echo $this->Form->end('Save File');
?>

0 个答案:

没有答案