Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony2][Doctrine]dlaczego generate:doctrine:entities nie generuje metod?
twojastara
post 6.02.2015, 21:44:20
Post #1





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


Chciałbym wygenerować automatycznie metody dla modeli powiązanych relacjami wg dokumentacji http://symfony.com/doc/current/cookbook/do...ngineering.html .

Robię to komendą generate:doctrine:entities i nic, nie dodaje żadnych metod, mimo że konsola nie wyrzuca błędów.




Od początku.

Wygenerowałem bazę na podstawie diagramu ER i utworzyłem ją na serwerze. Tę bazę komendą doctrine:mapping:import i doctrine:mapping:convert annotation i doctrine:generate:entities sprowadziłem do projektu Symfony i utworzyłem modele.

Dokumentacja mówi, że te komendy nie generują w pełni kodu i trzeba ręcznie dodać parę rzeczy.
(If you want to have a one-to-many relationship, you will need to add it manually into the entity or to the generated XML or YAML files. Add a section on the specific entities for one-to-many defining the inversedBy and the mappedBy pieces.)

Dodałem brakujące adnotacje relacji OneToMany i zmodyfikowałem relacje ManyToOne . Po tych zmianach uruchomiłem komendę doctrine:generate:entities i w efekcie nie dodał do klas żadnych nowych metod takich jak __construct() czy addxxx().



Co źle robię?



Dla przykładu wkleję dwa modele powiązane relacją ManyToOne. Ręcznie dodałem adnotacje OneToMany w klasie Kategoria.php i zmodyfikowałem ManyToOne w klasie Ksiazka.php.

ręcznie dodałem kod linii 32-35
  1. #Kategoria.php
  2. <?php
  3.  
  4. namespace AppBundle\Entity;
  5.  
  6. use Doctrine\ORM\Mapping as ORM;
  7.  
  8. /**
  9.  * Kategoria
  10.  *
  11.  * @ORM\Table(name="kategoria")
  12.  * @ORM\Entity
  13.  */
  14. class Kategoria
  15. {
  16. /**
  17.   * @var string
  18.   *
  19.   * @ORM\Column(name="nazwa", type="string", length=45, nullable=true)
  20.   */
  21. private $nazwa;
  22.  
  23. /**
  24.   * @var integer
  25.   *
  26.   * @ORM\Column(name="idKategoria", type="integer")
  27.   * @ORM\Id
  28.   * @ORM\GeneratedValue(strategy="IDENTITY")
  29.   */
  30. private $idkategoria;
  31.  
  32. /**
  33.   * @ORM\OneToMany(targetEntity="Ksiazka", mappedBy="kategoria")
  34.   */
  35. protected $ksiazki;
  36.  
  37. /**
  38.   * Set nazwa
  39.   *
  40.   * @param string $nazwa
  41.   * @return Kategoria
  42.   */
  43. public function setNazwa($nazwa)
  44. {
  45. $this->nazwa = $nazwa;
  46.  
  47. return $this;
  48. }
  49.  
  50. /**
  51.   * Get nazwa
  52.   *
  53.   * @return string
  54.   */
  55. public function getNazwa()
  56. {
  57. return $this->nazwa;
  58. }
  59.  
  60. /**
  61.   * Get idkategoria
  62.   *
  63.   * @return integer
  64.   */
  65. public function getIdkategoria()
  66. {
  67. return $this->idkategoria;
  68. }
  69. }
  70.  


modyfikowałem kod linii 78-86
  1. Ksiazka.php
  2. <?php
  3.  
  4. namespace AppBundle\Entity;
  5.  
  6. use Doctrine\ORM\Mapping as ORM;
  7.  
  8. /**
  9.  * Ksiazka
  10.  *
  11.  * @ORM\Table(name="ksiazka", indexes={@ORM\Index(name="idKategoria_idx", columns={"idKategoria"})})
  12.  * @ORM\Entity
  13.  */
  14. class Ksiazka
  15. {
  16. /**
  17.   * @var string
  18.   *
  19.   * @ORM\Column(name="autor", type="string", length=45, nullable=true)
  20.   */
  21. private $autor;
  22.  
  23. /**
  24.   * @var string
  25.   *
  26.   * @ORM\Column(name="opis", type="text", length=65535, nullable=true)
  27.   */
  28. private $opis;
  29.  
  30. /**
  31.   * @var string
  32.   *
  33.   * @ORM\Column(name="cena", type="decimal", precision=10, scale=2, nullable=true)
  34.   */
  35. private $cena;
  36.  
  37. /**
  38.   * @var string
  39.   *
  40.   * @ORM\Column(name="obrazek", type="string", length=45, nullable=true)
  41.   */
  42. private $obrazek;
  43.  
  44. /**
  45.   * @var string
  46.   *
  47.   * @ORM\Column(name="wydawnictwo", type="string", length=45, nullable=true)
  48.   */
  49. private $wydawnictwo;
  50.  
  51. /**
  52.   * @var string
  53.   *
  54.   * @ORM\Column(name="rokWydania", type="string", length=45, nullable=true)
  55.   */
  56. private $rokwydania;
  57.  
  58. /**
  59.   * @var string
  60.   *
  61.   * @ORM\Column(name="isbn", type="string", length=45)
  62.   * @ORM\Id
  63.   * @ORM\GeneratedValue(strategy="IDENTITY")
  64.   */
  65. private $isbn;
  66.  
  67. // Było. Automatycznie wygenerowane bez inversedBy.
  68. // /**
  69. // * @var \AppBundle\Entity\Kategoria
  70. // *
  71. // * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Kategoria")
  72. // * @ORM\JoinColumns({
  73. // * @ORM\JoinColumn(name="idKategoria", referencedColumnName="idKategoria")
  74. // * })
  75. // */
  76. // private $idkategoria;
  77.  
  78. /**
  79.   * @var \AppBundle\Entity\Kategoria
  80.   *
  81.   * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Kategoria", inversedBy="ksiazki")
  82.   * @ORM\JoinColumns({
  83.   * @ORM\JoinColumn(name="idKategoria", referencedColumnName="idKategoria")
  84.   * })
  85.   */
  86. private $kategoria;
  87.  
  88. /**
  89.   * @ORM\OneToMany(targetEntity="Zamowienie_Produkt", mappedBy="ksiazka")
  90.   */
  91. protected $zamowienie_produkty;
  92.  
  93.  
  94. /**
  95.   * Set autor
  96.   *
  97.   * @param string $autor
  98.   * @return Ksiazka
  99.   */
  100. public function setAutor($autor)
  101. {
  102. $this->autor = $autor;
  103.  
  104. return $this;
  105. }
  106.  
  107. /**
  108.   * Get autor
  109.   *
  110.   * @return string
  111.   */
  112. public function getAutor()
  113. {
  114. return $this->autor;
  115. }
  116.  
  117. /**
  118.   * Set opis
  119.   *
  120.   * @param string $opis
  121.   * @return Ksiazka
  122.   */
  123. public function setOpis($opis)
  124. {
  125. $this->opis = $opis;
  126.  
  127. return $this;
  128. }
  129.  
  130. /**
  131.   * Get opis
  132.   *
  133.   * @return string
  134.   */
  135. public function getOpis()
  136. {
  137. return $this->opis;
  138. }
  139.  
  140. /**
  141.   * Set cena
  142.   *
  143.   * @param string $cena
  144.   * @return Ksiazka
  145.   */
  146. public function setCena($cena)
  147. {
  148. $this->cena = $cena;
  149.  
  150. return $this;
  151. }
  152.  
  153. /**
  154.   * Get cena
  155.   *
  156.   * @return string
  157.   */
  158. public function getCena()
  159. {
  160. return $this->cena;
  161. }
  162.  
  163. /**
  164.   * Set obrazek
  165.   *
  166.   * @param string $obrazek
  167.   * @return Ksiazka
  168.   */
  169. public function setObrazek($obrazek)
  170. {
  171. $this->obrazek = $obrazek;
  172.  
  173. return $this;
  174. }
  175.  
  176. /**
  177.   * Get obrazek
  178.   *
  179.   * @return string
  180.   */
  181. public function getObrazek()
  182. {
  183. return $this->obrazek;
  184. }
  185.  
  186. /**
  187.   * Set wydawnictwo
  188.   *
  189.   * @param string $wydawnictwo
  190.   * @return Ksiazka
  191.   */
  192. public function setWydawnictwo($wydawnictwo)
  193. {
  194. $this->wydawnictwo = $wydawnictwo;
  195.  
  196. return $this;
  197. }
  198.  
  199. /**
  200.   * Get wydawnictwo
  201.   *
  202.   * @return string
  203.   */
  204. public function getWydawnictwo()
  205. {
  206. return $this->wydawnictwo;
  207. }
  208.  
  209. /**
  210.   * Set rokwydania
  211.   *
  212.   * @param string $rokwydania
  213.   * @return Ksiazka
  214.   */
  215. public function setRokwydania($rokwydania)
  216. {
  217. $this->rokwydania = $rokwydania;
  218.  
  219. return $this;
  220. }
  221.  
  222. /**
  223.   * Get rokwydania
  224.   *
  225.   * @return string
  226.   */
  227. public function getRokwydania()
  228. {
  229. return $this->rokwydania;
  230. }
  231.  
  232. /**
  233.   * Get isbn
  234.   *
  235.   * @return string
  236.   */
  237. public function getIsbn()
  238. {
  239. return $this->isbn;
  240. }
  241.  
  242. /**
  243.   * Set idkategoria
  244.   *
  245.   * @param \AppBundle\Entity\Kategoria $idkategoria
  246.   * @return Ksiazka
  247.   */
  248. public function setIdkategoria(\AppBundle\Entity\Kategoria $idkategoria = null)
  249. {
  250. $this->idkategoria = $idkategoria;
  251.  
  252. return $this;
  253. }
  254.  
  255. /**
  256.   * Get idkategoria
  257.   *
  258.   * @return \AppBundle\Entity\Kategoria
  259.   */
  260. public function getIdkategoria()
  261. {
  262. return $this->idkategoria;
  263. }
  264. /**
  265.   * @var \AppBundle\Entity\Kategoria
  266.   */
  267. private $idkategoria;
  268.  
  269.  
  270. }
  271.  


Ten post edytował twojastara 6.02.2015, 22:18:21
Go to the top of the page
+Quote Post
destroyerr
post 6.02.2015, 22:36:25
Post #2





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

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


To są raczej generatory z doctrine, ale nie zmienia to faktu, że nie może tych encji wygenerować skoro już są wygenerowane. Doctrine zwyczajnie w świecie ma bardzo ubogi generator encji, co jest dla mnie zrozumiałe, bo ORM ma mapować obiekty do bazy, a nie bazę do obiektów.

Jeszcze teraz mi się rzucił w oczy getter i setter dla id kategoria, zupełnie niepotrzebne. Interesują nas obiekty a nie ich identyfikatory.

Ten post edytował destroyerr 6.02.2015, 22:37:46
Go to the top of the page
+Quote Post
twojastara
post 6.02.2015, 22:49:55
Post #3





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


ale zdaje się, że komenda doctrine:generate:entities aktualizuje model o dodatkowe metody po dodaniu nowych właściwości?

(Z innej beczki. To jak to się profesjonalnie robi ? Myślałem, że najpierw projektuje się bazę, diagramy a dopiero potem modele w projekcie Symfony. No ale widzę, że w internetach nie wiele tematów dotyczących reverse engineering)

Ten post edytował twojastara 6.02.2015, 22:52:50
Go to the top of the page
+Quote Post
pyro
post 6.02.2015, 22:58:51
Post #4





Grupa: Zarejestrowani
Postów: 2 148
Pomógł: 230
Dołączył: 26.03.2008

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


Cytat(twojastara @ 6.02.2015, 22:49:55 ) *
Myślałem, że najpierw projektuje się bazę, diagramy a dopiero potem modele w projekcie Symfony.


Ale diagramu modeli nie można wykonać czy co?

// EDIT

Proponuję się zapoznać z definicją ORMa

Ten post edytował pyro 6.02.2015, 23:00:21


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
twojastara
post 6.02.2015, 23:02:23
Post #5





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


w szkołach kazali zaczynać od diagramów ER.
To od czego Wy rozpoczynacie projekty (proste), od pisania klas modeli?
----

No dobrze, ale wracając do istoty. Gdzie jest błąd, że komenda generate:doctrine:entities nie generuje metod __contruct i addXXX() w modelu Kategoria ?

----

Z podręcznika Gajdy:

Użycie relacji 1:n w Symfony 2
W Symfony 2 relacje 1:n definiujemy adnotacjami:
@ORM\OneToMany(...)
@ORM\ManyToOne(...)

W klasie Entity odpowiadającej tabeli źródłowej dodajemy adnotację @ORM\OneToMany ,
a w klasie odpowiadającej tabeli docelowej ? adnotację @ORM\ManyToOne . Powiązanie
tabel kontynent oraz panstwo jest zilustrowane na listingach 32.2 oraz 32.3.

  1. #Listing 32.2. Właściwość i adnotacja definiujące relację 1:n w klasie źródłowej kontynent
  2. class Kontynent
  3. {
  4. ...
  5. /**
  6. * @ORM\OneToMany(targetEntity="Panstwo", mappedBy="kontynent")
  7. */
  8. protected $panstwa;
  9. ...
  10. }



  1. #Listing 32.3. Właściwość i adnotacja definiujące relację 1:n w klasie docelowej panstwo
  2. class Panstwo
  3. {
  4. ...
  5. /**
  6. * @ORM\ManyToOne(targetEntity="Kontynent", inversedBy="panstwa")
  7. */
  8. protected $kontynent;
  9. ...
  10. }



Po dodaniu w klasach Kontynent oraz Panstwo właściwości z listingów 32.2 oraz 32.3
wydajemy polecenie:
php app/console generate:doctrine:entities My
Spowoduje ono dodanie w klasie Kontynent metod przedstawionych na listingu 32.4 oraz
w klasie Panstwo metod przedstawionych na listingu 32.5.

  1. #Listing 32.4. Metody klasy Kontynent wygenerowane automatycznie dla właściwości z listingu 32.2
  2. class Kontynent
  3. {
  4. ...
  5. public function __construct()
  6. {
  7. $this->panstwa = new \Doctrine\Common\Collections\ArrayCollection();
  8. }
  9. /**
  10. * Add panstwa
  11. *
  12. * @param My\FrontendBundle\Entity\Panstwo $panstwa
  13. */
  14. public function addPanstwo(\My\FrontendBundle\Entity\Panstwo $panstwa)
  15. {
  16. $this->panstwa[] = $panstwa;
  17. }
  18. /**
  19. * Get panstwa
  20. *
  21. * @return Doctrine\Common\Collections\Collection
  22. */
  23. public function getPanstwa()
  24. {
  25. return $this->panstwa;
  26. }
  27. ...
  28. }


Ten post edytował twojastara 7.02.2015, 00:25:26
Go to the top of the page
+Quote Post
destroyerr
post 7.02.2015, 12:37:06
Post #6





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

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


Odświeżyłem swoją wiedzę na temat generowania encji. Skorzystaj z pomocy tego polecenia i zobaczysz opcje takie jak: update-entities i regenerate-entities.
Go to the top of the page
+Quote Post
twojastara
post 7.02.2015, 17:58:59
Post #7





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


w helpie doctrine:generate:entities?

nic tam nie widzę o tym co piszesz.
Go to the top of the page
+Quote Post
destroyerr
post 8.02.2015, 10:23:09
Post #8





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

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


Na ten problem ciężko jest podać rozwiązanie, bo nie wiadomo, czy nie możesz otworzyć tej pomocy, czy nie rozumiesz angielskiego czy jest jakiś inny powód. Tutaj też nie widzisz nic na ten temat?
Go to the top of the page
+Quote Post
twojastara
post 17.02.2015, 15:58:23
Post #9





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (10%)
X----


dzięki, sprawdzę to na pewno (później).



"Skorzystaj z pomocy tego polecenia i zobaczysz opcje takie jak: update-entities i regenerate-entities."
  1. $ php app/console doctrine:generate:entities --help
  2. Usage:
  3. doctrine:generate:entities [--path="..."] [--no-backup] name
  4.  
  5. Aliases: generate:doctrine:entities
  6. Arguments:
  7. name A bundle name, a namespace, or a class name
  8.  
  9. Options:
  10. --path The path where to generate entities when it cannot be gue
  11. ssed
  12. --no-backup Do not backup existing entities files.
  13. --help (-h) Display this help message
  14. --quiet (-q) Do not output any message
  15. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output,
  16. 2 for more verbose output and 3 for debug
  17. --version (-V) Display this application version
  18. --ansi Force ANSI output
  19. --no-ansi Disable ANSI output
  20. --no-interaction (-n) Do not ask any interactive question
  21. --shell (-s) Launch the shell.
  22. --process-isolation Launch commands from shell as a separate process.
  23. --env (-e) The Environment name. (default: "dev")
  24. --no-debug Switches off debug mode.
  25.  
  26. Help:
  27. The doctrine:generate:entities command generates entity classes
  28. and method stubs from your mapping information:
  29.  
  30. You have to limit generation of entities:
  31.  
  32. * To a bundle:
  33.  
  34. php app/console doctrine:generate:entities MyCustomBundle
  35.  
  36. * To a single entity:
  37.  
  38. php app/console doctrine:generate:entities MyCustomBundle:User
  39. php app/console doctrine:generate:entities MyCustomBundle/Entity/User
  40.  
  41. * To a namespace
  42.  
  43. php app/console doctrine:generate:entities MyCustomBundle/Entity
  44.  
  45. If the entities are not stored in a bundle, and if the classes do not exist,
  46. the command has no way to guess where they should be generated. In this case,
  47. you must provide the --path option:
  48.  
  49. php app/console doctrine:generate:entities Blog/Entity --path=src/
  50.  
  51. By default, the unmodified version of each entity is backed up and saved
  52. (e.g. Product.php~). To prevent this task from creating the backup file,
  53. pass the --no-backup option:
  54.  
  55. php app/console doctrine:generate:entities Blog/Entity --no-backup
  56.  
  57. Important: Even if you specified Inheritance options in your
  58. XML or YAML Mapping files the generator cannot generate the base and
  59. child classes for you correctly, because it doesn't know which
  60. class is supposed to extend which. You have to adjust the entity
  61. code manually for inheritance to work!
  62.  
  63.  
  64. chin@CHINY /C/wamp/www/Szobuk2


u mnie użycie komendy

  1. doctrine:generate:entities AppBundle:Ksiazka --update-entities


powoduje

  1. [RuntimeException]
  2. The "--update-entities" option does not exist.


ale, tak jak piszesz, istnieje i w moim projekcie klasa z opcjami update i regenerate

  1. #\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCom
    mand.php
  2. <?php
  3. /*
  4.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  5.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  6.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  7.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  9.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  10.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  11.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  12.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  13.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  14.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15.  *
  16.  * This software consists of voluntary contributions made by many individuals
  17.  * and is licensed under the MIT license. For more information, see
  18.  * <http://www.doctrine-project.org>.
  19.  */
  20.  
  21. namespace Doctrine\ORM\Tools\Console\Command;
  22.  
  23. use Symfony\Component\Console\Input\InputArgument;
  24. use Symfony\Component\Console\Input\InputOption;
  25. use Doctrine\ORM\Tools\Console\MetadataFilter;
  26. use Doctrine\ORM\Tools\EntityGenerator;
  27. use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Command\Command;
  31.  
  32. /**
  33.  * Command to generate entity classes and method stubs from your mapping information.
  34.  *
  35.  * @link www.doctrine-project.org
  36.  * @since 2.0
  37.  * @author Benjamin Eberlei <kontakt@beberlei.de>
  38.  * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  39.  * @author Jonathan Wage <jonwage@gmail.com>
  40.  * @author Roman Borschel <roman@code-factory.org>
  41.  */
  42. class GenerateEntitiesCommand extends Command
  43. {
  44. /**
  45.   * {@inheritdoc}
  46.   */
  47. protected function configure()
  48. {
  49. $this
  50. ->setName('orm:generate-entities')
  51. ->setAliases(array('orm:generate:entities'))
  52. ->setDescription('Generate entity classes and method stubs from your mapping information.')
  53. ->setDefinition(array(
  54. new InputOption(
  55. 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
  56. 'A string pattern used to match entities that should be processed.'
  57. ),
  58. new InputArgument(
  59. 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.'
  60. ),
  61. new InputOption(
  62. 'generate-annotations', null, InputOption::VALUE_OPTIONAL,
  63. 'Flag to define if generator should generate annotation metadata on entities.', false
  64. ),
  65. new InputOption(
  66. 'generate-methods', null, InputOption::VALUE_OPTIONAL,
  67. 'Flag to define if generator should generate stub methods on entities.', true
  68. ),
  69. new InputOption(
  70. 'regenerate-entities', null, InputOption::VALUE_OPTIONAL,
  71. 'Flag to define if generator should regenerate entity if it exists.', false
  72. ),
  73. new InputOption(
  74. 'update-entities', null, InputOption::VALUE_OPTIONAL,
  75. 'Flag to define if generator should only update entity if it exists.', true
  76. ),
  77. new InputOption(
  78. 'extend', null, InputOption::VALUE_OPTIONAL,
  79. 'Defines a base class to be extended by generated entity classes.'
  80. ),
  81. new InputOption(
  82. 'num-spaces', null, InputOption::VALUE_OPTIONAL,
  83. 'Defines the number of indentation spaces', 4
  84. )
  85. ))
  86. ->setHelp(<<<EOT
  87. Generate entity classes and method stubs from your mapping information.
  88.  
  89. If you use the <comment>--update-entities</comment> or <comment>--regenerate-entities</comment> flags your existing
  90. code gets overwritten. The EntityGenerator will only append new code to your
  91. file and will not delete the old code. However this approach may still be prone
  92. to error and we suggest you use code repositories such as GIT or SVN to make
  93. backups of your code.
  94.  
  95. It makes sense to generate the entity code if you are using entities as Data
  96. Access Objects only and don't put much additional logic on them. If you are
  97. however putting much more logic on the entities you should refrain from using
  98. the entity-generator and code your entities manually.
  99.  
  100. <error>Important:</error> Even if you specified Inheritance options in your
  101. XML or YAML Mapping files the generator cannot generate the base and
  102. child classes for you correctly, because it doesn't know which
  103. class is supposed to extend which. You have to adjust the entity
  104. code manually for inheritance to work!
  105. EOT
  106. );
  107. }
  108.  
  109. /**
  110.   * {@inheritdoc}
  111.   */
  112. protected function execute(InputInterface $input, OutputInterface $output)
  113. {
  114. $em = $this->getHelper('em')->getEntityManager();
  115.  
  116. $cmf = new DisconnectedClassMetadataFactory();
  117. $cmf->setEntityManager($em);
  118. $metadatas = $cmf->getAllMetadata();
  119. $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
  120.  
  121. // Process destination directory
  122. $destPath = realpath($input->getArgument('dest-path'));
  123.  
  124. if ( ! file_exists($destPath)) {
  125. throw new \InvalidArgumentException(
  126. sprintf("Entities destination directory '<info>%s</info>' does not exist.", $input->getArgument('dest-path'))
  127. );
  128. }
  129.  
  130. if ( ! is_writable($destPath)) {
  131. throw new \InvalidArgumentException(
  132. sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath)
  133. );
  134. }
  135.  
  136. if (count($metadatas)) {
  137. // Create EntityGenerator
  138. $entityGenerator = new EntityGenerator();
  139.  
  140. $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
  141. $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
  142. $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
  143. $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
  144. $entityGenerator->setNumSpaces($input->getOption('num-spaces'));
  145.  
  146. if (($extend = $input->getOption('extend')) !== null) {
  147. $entityGenerator->setClassToExtend($extend);
  148. }
  149.  
  150. foreach ($metadatas as $metadata) {
  151. $output->writeln(
  152. sprintf('Processing entity "<info>%s</info>"', $metadata->name)
  153. );
  154. }
  155.  
  156. // Generating Entities
  157. $entityGenerator->generate($metadatas, $destPath);
  158.  
  159. // Outputting information message
  160. $output->writeln(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath));
  161. } else {
  162. $output->writeln('No Metadata Classes to process.');
  163. }
  164. }
  165. }
Go to the top of the page
+Quote Post
destroyerr
post 24.02.2015, 20:51:15
Post #10





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

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


Oj, przepraszam, nie zauważyłem, że symfony ma swój generator encji.
Go to the top of the page
+Quote Post
prz3kus
post 25.02.2015, 15:37:19
Post #11





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

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


Troszkę się chyba wyłamałeś tworząc strukturę projektu w klasach masz
namespace AppBundle\Entity;

gdzie indziej piszesz
\My\FrontendBundle\Entity

Powiedz dokładnie jaka jest ściezka do klasy co chcesz zrobic update, i wywal wszystkie metody get i set przy tym co sie nie robi update i wywołaj bez żadnych parametrów dodatkowych

php app/console doctrine:generate:entities My
(jezeli twój entityjest pod srv/My/FrontendBundle/Entity)

nie

generate:doctrine:entities

Pozdrawiam

Ten post edytował prz3kus 25.02.2015, 15:39:24
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 13.05.2024 - 21:06