Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CategoryAdmin
- protected function configureFormFields(FormMapper $form)
- {
- $form
- ->add('name',TextType::class)
- ->add('products',EntityType::class,
- [
- 'class' => Product::class,
- 'property' => 'name',
- 'required' => false,
- ]);
- }
- <?php
- namespace AppBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * Category
- *
- * @ORM\Table(name="category")
- * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
- */
- class Category
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="name", type="string", length=255, unique=true)
- */
- private $name;
- /**
- * @ORM\OneToMany(targetEntity="Product", mappedBy="category")
- */
- private $products;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="createdAt", type="datetime")
- */
- private $createdAt;
- /**
- * @var string
- *
- * @ORM\Column(name="updatedAt", type="string", length=255)
- */
- private $updatedAt;
- public function __toString()
- {
- return $this->name;
- }
- /**
- * @ORM\PrePersist()
- */
- public function setCreatedDate()
- {
- $this->createdAt = new \DateTime();
- $this->updatedAt = new \DateTime();
- }
- /**
- * @ORM\PreUpdate()
- */
- public function setUpdateDate()
- {
- $this->updatedAt = new \DateTime();
- }
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->products = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set name
- *
- * @param string $name
- *
- * @return Category
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * Get name
- *
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * Set createdAt
- *
- * @param \DateTime $createdAt
- *
- * @return Category
- */
- public function setCreatedAt($createdAt)
- {
- $this->createdAt = $createdAt;
- return $this;
- }
- /**
- * Get createdAt
- *
- * @return \DateTime
- */
- public function getCreatedAt()
- {
- return $this->createdAt;
- }
- /**
- * Set updatedAt
- *
- * @param string $updatedAt
- *
- * @return Category
- */
- public function setUpdatedAt($updatedAt)
- {
- $this->updatedAt = $updatedAt;
- return $this;
- }
- /**
- * Get updatedAt
- *
- * @return string
- */
- public function getUpdatedAt()
- {
- return $this->updatedAt;
- }
- /**
- * Add product
- *
- * @param \AppBundle\Entity\Product $product
- *
- * @return Category
- */
- public function addProduct(\AppBundle\Entity\Product $product = null)
- {
- $this->products[] = $product;
- return $this;
- }
- /**
- * Remove product
- *
- * @param \AppBundle\Entity\Product $product
- */
- public function removeProduct(\AppBundle\Entity\Product $product)
- {
- $this->products->removeElement($product);
- }
- /**
- * Get products
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getProducts()
- {
- return $this->products;
- }
- }
- <?php
- namespace AppBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * Product
- *
- * @ORM\Table(name="product")
- * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
- * @ORM\HasLifecycleCallbacks()
- */
- class Product
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="name", type="string", length=255, unique=true)
- */
- private $name;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="createdAt", type="datetime")
- */
- private $createdAt;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="updatedAt", type="datetime")
- */
- private $updatedAt;
- /**
- * @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
- * @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
- */
- private $category;
- /**
- * THIS ALLOW TO SHOW PRETTY NAME
- * Item "IPHONE" has been successfully created.
- * INSTEAD OF :
- * Item "AppBundle\Entity\Product:00000000386cfe5f00000000bdb77d26" has been successfully created.
- * @return string
- */
- public function __toString()
- {
- return $this->name;
- }
- /**
- * @ORM\PrePersist()
- */
- public function setCreatedDate()
- {
- $this->createdAt = new \DateTime();
- $this->updatedAt = new \DateTime();
- }
- /**
- * @ORM\PreUpdate()
- */
- public function setUpdateDate()
- {
- $this->updatedAt = new \DateTime();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set name
- *
- * @param string $name
- *
- * @return Product
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * Get name
- *
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * Set createdAt
- *
- * @param \DateTime $createdAt
- *
- * @return Product
- */
- public function setCreatedAt($createdAt)
- {
- $this->createdAt = $createdAt;
- return $this;
- }
- /**
- * Get createdAt
- *
- * @return \DateTime
- */
- public function getCreatedAt()
- {
- return $this->createdAt;
- }
- /**
- * Set updatedAt
- *
- * @param \DateTime $updatedAt
- *
- * @return Product
- */
- public function setUpdatedAt($updatedAt)
- {
- $this->updatedAt = $updatedAt;
- return $this;
- }
- /**
- * Get updatedAt
- *
- * @return \DateTime
- */
- public function getUpdatedAt()
- {
- return $this->updatedAt;
- }
- /**
- * Set category
- *
- * @param \AppBundle\Entity\Category $category
- *
- * @return Product
- */
- public function setCategory(\AppBundle\Entity\Category $category = null)
- {
- $this->category = $category;
- return $this;
- }
- /**
- * Get category
- *
- * @return \AppBundle\Entity\Category
- */
- public function getCategory()
- {
- return $this->category;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement