0
我使用CakePHP 3.2和proffer插件上傳圖像。在cakephp中使用proffer進行多圖像上傳
我有products
和product_images
表和使用單個表單上傳數據到兩個表。
這是我的形式是如何
<?= $this->Form->create($product, ['type' => 'file') ?>
<?= $this->Form->input('title', ['required' => true]) ?>
<?= $this->Form->input('description', ['required' => true]) ?>
<?= $this->Form->input('product_images.0.image', ['required' => true, 'type' => 'file']) ?>
<?= $this->Form->input('product_images.1.image', ['type' => 'file']) ?>
<?= $this->Form->button('submit', ['type' => 'submit']) ?>
<?= $this->Form->end() ?>
和控制器就像是
public function add()
{
$product = $this->Products->newEntity();
if ($this->request->is('post')) {
$product = $this->Products->patchEntity($product, $this->request->data, [
'associated' => ['ProductImages']
]);
if ($this->Products->save($product)) {
$this->Flash->success('Product saved');
}
}
}
但這將數據保存到產品表,而不是產品的圖片。