Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][doctrine] Dodawanie klucza obcego do encji? Terminal wyświetla błąd., Invalid index-name cat-id given, has to be [a-zA-Z0-9_]
starterrrrr
post
Post #1





Grupa: Zarejestrowani
Postów: 138
Pomógł: 0
Dołączył: 7.01.2015

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


Witam.
Przerabiam sobie pewien tutorial z youtube i dokłądnie w miejscu do którego dałem link: https://www.youtube.com/watch?v=MS4LICZ1j0s&t=251s
Napotykam na problem. Pojawia się komunikat:

Cytat
In SchemaException.php line 44:

Invalid index-name cat-id given, has to be [a-zA-Z0-9_]


Z tego co rozumie, to komunikat ten mówi, że index o nazwie cat-id jest niepoprawny, z tego co widzę znak "-" jest niedozwolony.

Dziwna sprawa, bo tylko dodałem dwie encje poprzez bin/console tak jak na filmie. Dodałem klucz obcy dla dwóch encji i pojawia się ten błąd. Robie dokłądnie to co w tutorialu.

  1.  
  2. <?php
  3. //plik Post.php
  4.  
  5. namespace App\Entity;
  6.  
  7. use App\Repository\PostRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9.  
  10. /**
  11.  * @ORM\Entity(repositoryClass=PostRepository::class)
  12.  */
  13. class Post
  14. {
  15. /**
  16.   * @ORM\Id
  17.   * @ORM\GeneratedValue
  18.   * @ORM\Column(type="integer")
  19.   */
  20. private $id;
  21.  
  22. /**
  23.   * @ORM\Column(type="string", length=255)
  24.   */
  25. private $title;
  26.  
  27. /**
  28.   * @ORM\Column(type="text")
  29.   */
  30. private $content;
  31.  
  32. //tutaj $category dodana recznie
  33. /**
  34.   * @ORM\ManyToOne(targetEntity="Category", inversedBy="posts")
  35.   */
  36. private $category;
  37.  
  38. public function getId(): ?int
  39. {
  40. return $this->id;
  41. }
  42.  
  43. public function getTitle(): ?string
  44. {
  45. return $this->title;
  46. }
  47.  
  48. public function setTitle(string $title): self
  49. {
  50. $this->title = $title;
  51.  
  52. return $this;
  53. }
  54.  
  55. public function getContent(): ?string
  56. {
  57. return $this->content;
  58. }
  59.  
  60. public function setContent(string $content): self
  61. {
  62. $this->content = $content;
  63.  
  64. return $this;
  65. }
  66.  
  67. public function getCategory(): ?Category
  68. {
  69. return $this->category;
  70. }
  71.  
  72. public function setCategory(?Category $category): self
  73. {
  74. $this->category = $category;
  75.  
  76. return $this;
  77. }
  78. }




  1. <?php
  2.  
  3. //Plik Category.php
  4.  
  5. namespace App\Entity;
  6.  
  7. use App\Repository\CategoryRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11.  
  12. /**
  13.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  14.  */
  15. class Category
  16. {
  17. /**
  18.   * @ORM\Id
  19.   * @ORM\GeneratedValue
  20.   * @ORM\Column(type="integer")
  21.   */
  22. private $id;
  23.  
  24. /**
  25.   * @ORM\Column(type="string", length=255)
  26.   */
  27. private $name;
  28.  
  29. //tutaj $posts dodana recznie
  30. /**
  31.   * @ORM\OneToMany(targetEntity="Post", mappedBy="category")
  32.   */
  33. private $posts;
  34.  
  35. public function __construct()
  36. {
  37. $this->posts = new ArrayCollection();
  38. }
  39.  
  40. public function getId(): ?int
  41. {
  42. return $this->id;
  43. }
  44.  
  45. public function getName(): ?string
  46. {
  47. return $this->name;
  48. }
  49.  
  50. public function setName(string $name): self
  51. {
  52. $this->name = $name;
  53.  
  54. return $this;
  55. }
  56.  
  57. /**
  58.   * @return Collection|Posts[]
  59.   */
  60. public function getPosts(): Collection
  61. {
  62. return $this->posts;
  63. }
  64.  
  65. public function addPost(Posts $post): self
  66. {
  67. if (!$this->posts->contains($post)) {
  68. $this->posts[] = $post;
  69. $post->setCategory($this);
  70. }
  71.  
  72. return $this;
  73. }
  74.  
  75. public function removePost(Posts $post): self
  76. {
  77. if ($this->posts->removeElement($post)) {
  78. // set the owning side to null (unless already changed)
  79. if ($post->getCategory() === $this) {
  80. $post->setCategory(null);
  81. }
  82. }
  83.  
  84. return $this;
  85. }
  86. }
  87.  



Co robie nie tak, czy mogę gdzies podać nazawę tego klucza? Próbowałem różne kombinacje, i juz brak pomysłów.

Ten post edytował starterrrrr 8.02.2021, 11:52:50
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 - 01:41