Answer the question
In order to leave comments, you need to log in
How to specify multiple sections when adding a product?
Hello.
Symfony 4.2.3. When adding a product, I want to display several drop-down lists with the same name, i.e. categories[0], categories[1], etc. to specify the sections in which the added product will be located. Can't figure out how to implement this?
entity category:
class Category
{
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product", inversedBy="categories")
* @ORM\JoinTable(name="categories_products", joinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}, inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")})
*/
private $products;
}
class Product
{
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Category", mappedBy="products")
*/
private $categories;
/**
* Product constructor.
*/
public function __construct()
{
$this->categories = new ArrayCollection();
}
/**
* @return ArrayCollection
*/
public function getCategories(): ArrayCollection
{
return $this->categories;
}
}
Answer the question
In order to leave comments, you need to log in
bears , thanks for your help. So far I did it the way you suggested. There was an idea how to implement what I wanted, but I need to try. The page https://symfony.com/doc/current/reference/forms/ty... has a subsection called "Adding and Removing Items" that tells you how to add more to two existing fields using jQuery. But no one forbids us when adding a product, after loading the page, using the same jQuery to add one drop-down list and a link to add additional ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question