Bonjour,bref j'ai un problème avec de la fonction __tostring :
bon tout simplement j'ai deux tables News et News_category :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 [Semantical Error] line 0, col 147 near 'id = :idNews': Error: Class Mysite\NewsBundle\Entity\NewsCategory has no field or association named id
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 /** * Mysite\NewsBundle\Entity\News * * @ORM\Table(name="news") * @ORM\Entity */ class News { /** * @var integer $idNews * * @ORM\Column(name="id_news", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idNews; ....... /** * @var NewsCategory * * @ORM\ManyToOne(targetEntity="NewsCategory" ) * @ORM\JoinColumns({ * @ORM\JoinColumn(name="id_news_category", referencedColumnName="id_news_category") * }) */ private $idNewsCategory; /** * Set idNewsCategory * * @param Mysite\NewsBundle\Entity\NewsCategory $idNewsCategory */ public function setIdNewsCategory(\Mysite\NewsBundle\Entity\NewsCategory $idNewsCategory) { $this->idNewsCategory = $idNewsCategory; } /** * Get idNewsCategory * * @return Mysite\NewsBundle\Entity\NewsCategory */ public function getIdNewsCategory() { return $this->idNewsCategory; }
et News_catogory :
Et j'utilise ce champs pour le filtrage des résultats dans Sonata Admin Bundle :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 /** * Mysite\NewsBundle\Entity\NewsCategory * * @ORM\Table(name="news_category") * @ORM\Entity */ class NewsCategory { /** * @var integer $idNewsCategory * * @ORM\Column(name="id_news_category", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idNewsCategory; /** * @var string $categoryName * * @ORM\Column(name="category_name", type="string", length=45, nullable=true) */ private $categoryName; /** * Get idNewsCategory * * @return integer */ public function getIdNewsCategory() { return $this->idNewsCategory; } /** * Set categoryName * * @param string $categoryName */ public function setCategoryName($categoryName) { $this->categoryName = $categoryName; } /** * Get categoryName * * @return string */ public function getCategoryName() { return $this->categoryName; } /** * Set slug * * @param string slug */ public function setSlug($slug) { $this->slug = $slug; } /** * Get slug * * @return string */ public function getSlug() { return $this->slug; } public function __toString() { return $this->getCategoryName(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 class NewsAdmin extends Admin { .... protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper .... ->add('idNewsCategory') ...... }
Bon sur le formulaire de recherche j’obtiens la liste des catégories mais quand j’effectue le filtrage des résultat j'aurai ce message d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 [Semantical Error] line 0, col 147 near 'id = :idNews': Error: Class Mysite\NewsBundle\Entity\NewsCategory has no field or association named id
C'est à dire pour la récupération de "CategoryName" sa marche bien mais le filtrage de de résultat qui ne fonctionne pas.
Partager