Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Doctrine]atrybuty category, subcategory w klasie products
alfredNN
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 19.12.2016

Ostrzeżenie: (0%)
-----


Witam, jakiś czas temu zacząłem przygodę z symfony 3.
Napotkałem problem z pobraniem atrybutów klasy "category" w klasie "product" gdy używam klasy subcategory.
Jak stworzyć relacje aby można było pobrać atrybut image z category i subcategory w klasie product.


klasa category
  1. <?php
  2. namespace AppBundle\Entity;
  3.  
  4. use Doctrine\ORM\Mapping as ORM;
  5.  
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="category")
  9.  */
  10.  
  11. class Category
  12. {
  13. /**
  14.   * @ORM\Column(type="integer")
  15.   * @ORM\Id
  16.   * @ORM\GeneratedValue(strategy="AUTO")
  17.   */
  18. private $id;
  19.  
  20. /**
  21.   * @ORM\OneToMany(targetEntity="Sybcategory", mappedBy="category")
  22.   */
  23. protected $category;
  24.  
  25. /**
  26.   * @ORM\Column(type="string", length=255, nullable=true)
  27.   */
  28. private $image;
  29.  
  30. }


klasa subcategory
  1. <?php
  2. namespace AppBundle\Entity;
  3.  
  4. use Doctrine\ORM\Mapping as ORM;
  5.  
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="subcategory")
  9.  */
  10.  
  11. class Subcategory
  12. {
  13. /**
  14.   * @ORM\Column(type="integer")
  15.   * @ORM\Id
  16.   * @ORM\GeneratedValue(strategy="AUTO")
  17.   */
  18. private $id;
  19.  
  20. /**
  21.   * @ORM\ManyToOne(targetEntity="Category", inversedBy="category")
  22.   */
  23. private $category;
  24.  
  25. /**
  26.   * @ORM\Column(type="string", length=255, nullable=true)
  27.   */
  28. private $image;
  29.  
  30. /**
  31.   * @ORM\OneToMany(targetEntity="Product", mappedBy="product")
  32.   */
  33. protected $product;
  34.  
  35. }


klasa product
  1. <?php
  2. namespace AppBundle\Entity;
  3.  
  4. use Doctrine\ORM\Mapping as ORM;
  5.  
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="product")
  9.  */
  10.  
  11. class Product
  12. {
  13. /**
  14.   * @ORM\Column(type="integer")
  15.   * @ORM\Id
  16.   * @ORM\GeneratedValue(strategy="AUTO")
  17.   */
  18. private $id;
  19.  
  20. /**
  21.   * @ORM\ManyToOne(targetEntity="Subcategory", inversedBy="subcategory")
  22.   */
  23. private $subcategory;
  24.  
  25. /**
  26.   * @ORM\Column(type="string", length=255, nullable=true)
  27.   */
  28. private $description;
  29. }

setery i getery generowane automatycznie.
Klasy są przykładowe.

Ten post edytował alfredNN 20.12.2016, 00:18:15
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 03:40