我有一个带有两个输入字段的表单,我希望将数据保存在一个表中的一个字段中,另一个字段保存在第二个表中。我的主要表是多媒体,第二个是描述。
我用它将一个文件保存到主表:
$multimedia->set('original_file', $original_filename);
我正在使用 CakePHP 3
修改
我的添加功能:
public function add()
{
$multimedia = $this->Multimedia->newEntity();
if ($this->request->is('post')) {
$multimedia = $this->Multimedia->patchEntity($multimedia, $this->request->data);
$hi = $this->data['Descriptions']['title'];
$bye = $this->data['Descriptions']['description'];
// Saving the file
$file = $_FILES['url'];
//$path = "webroot\\files\\" .$_FILES['url']['name']; //server
//Web File
$path = WWW_ROOT."files" .$_FILES['url']['name']; //Windows
$success = move_uploaded_file($_FILES['url']['tmp_name'], $path);
// Original File
$path = WWW_ROOT."files" .$_FILES['original_file']['name']; //Windows
$success = move_uploaded_file($_FILES['original_file']['tmp_name'], $path);
$filename = $_FILES['url']['name'];
$original_filename = $_FILES['original_file']['name'];
$created = $_SESSION['Auth']['User']['id'];
$type = mime_content_type($path);
$multimedia->set('mime_type', $type);
$multimedia->set('url', $filename);
$multimedia->set('original_file', $original_filename);
$multimedia->set('created_by', $created);
echo $multimedia;
echo "<br>";
echo $filename;
echo "<br>";
echo $hi;
exit();
if ($this->Multimedia->save($multimedia)) {
$this->Flash->success('The multimedia has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The multimedia could not be saved. Please, try again.');
}
}
$languages = $this->Multimedia->Languages->find('list', ['limit' => 200]);
$categories = $this->Multimedia->Categories->find('list', ['limit' => 200]);
$users = $this->Multimedia->Users->find('list', ['limit' => 200]);
$descriptions = $this->Multimedia->Descriptions->find('list', ['limit' => 200]);
$this->set(compact('multimedia', 'languages', 'categories', 'users', 'descriptions'));
$this->set('_serialize', ['multimedia']);
}