如何在CAKEPHP中对多个记录执行CRUD操作
我的任务是将文件上传到文件夹,并将其详细信息上传到数据库。如果我在表单中有一条记录,那么工作正常。但如果我有多行记录,那么它确实会出错。我搜索了许多链接,但找不到答案 使用了全部保存、全部保存、全部保存功能,但仍无法执行 请提供完整的代码,如果有人可以 我的控制器如何在CAKEPHP中对多个记录执行CRUD操作,cakephp,Cakephp,我的任务是将文件上传到文件夹,并将其详细信息上传到数据库。如果我在表单中有一条记录,那么工作正常。但如果我有多行记录,那么它确实会出错。我搜索了许多链接,但找不到答案 使用了全部保存、全部保存、全部保存功能,但仍无法执行 请提供完整的代码,如果有人可以 我的控制器 public function add() { if ($this->request->is('post')) { $this->File->create();
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');
?>
添加文件
如果我有多行,那么它真的会产生错误
-什么错误?它不会将表单字段映射到数据库,只是将最后一行映射到不是错误的数据库(消息)。现在还不清楚你有什么问题。我没有任何错误我的问题是我想保存超过1行到一个数据库,但我无法做到这一点我提交我的表格,但它只是保存一个记录不是所有这是没有帮助的,提供代码,做一件事-然后基本上要求别人提供代码给你做其他事情;问题中的代码似乎没有试图大容量保存任何内容。演示一个问题。如果我有多行,那么它真的会出错
-什么错误?它不会将表单字段映射到数据库,而是将最后一行映射到不是错误的数据库(消息)。现在还不清楚你有什么问题。我没有任何错误我的问题是我想保存超过1行到一个数据库,但我无法做到这一点我提交我的表格,但它只是保存一个记录不是所有这是没有帮助的,提供代码,做一件事-然后基本上要求别人提供代码给你做其他事情;问题中的代码似乎没有试图大容量保存任何内容。演示一个问题。