D
D
dkrylov2017-05-11 09:52:44
MySQL
dkrylov, 2017-05-11 09:52:44

Do I understand correctly the essence of uploading images to products?

Hello, yiisty)
I'm learning yii2, faced with the task of uploading photos for products.
There are 2 tables (exaggerated):
`product` - id | name (ID and product name)
`product_photo` - id | product_id | image (post ID, product ID, image link)
The question is how to attach uploaded photos to a product? I present so far as follows:
In the Product.php product model, add the $images property. When displaying a product model (editing in the admin panel) - display an additional input for multiple uploads:

<?= $form->field($model, 'images[]')->fileInput(['multiple' => true, 'accept' => 'image/*']) ?>

When sending, in the product model, use use to connect the ProductPhoto model. And when processing these files, add an entry to the database using this model.
Am I thinking right? Or is there a more elegant solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-05-11
@dkrylov

Good morning.
Basically correct.
First, do as you described.
It will work - look for a more elegant solution.
And you can share.
First, create a record in the product database, then, after you are redirected to the page for viewing the created product, attach images. Just add a form to upload images on the product view page.
There are many options, choose the one you like best.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question