framework-web:symfony:models

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
framework-web:symfony:models [2018/02/05 02:33] – [Configuration] jcheronframework-web:symfony:models [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1
Ligne 26: Ligne 26:
 <sxh bash;gutter:false> <sxh bash;gutter:false>
 php bin/console doctrine:database:create php bin/console doctrine:database:create
 +</sxh>
 +
 +===== Génération d'une classe métier =====
 +<sxh bash;gutter:false>
 +php bin/console make:entity Product
 +</sxh>
 +
 +Le code généré est le suivant :
 +<sxh php;title:src/Entity/Product.php>
 +namespace App\Entity;
 +
 +use Doctrine\ORM\Mapping as ORM;
 +
 +/**
 + * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 + */
 +class Product
 +{
 +    /**
 +     * @ORM\Id
 +     * @ORM\GeneratedValue
 +     * @ORM\Column(type="integer")
 +     */
 +    private $id;
 +
 +    // add your own fields
 +}
 +</sxh>
 +
 +===== Ajout d'attributs et mise à jour de la base =====
 +
 +Ajout des champs **name** et **price** :
 +<sxh php;title:src/Entity/Product.php;highlight:[17,18,19,20,21,22,23,24,25]>
 +namespace App\Entity;
 +
 +use Doctrine\ORM\Mapping as ORM;
 +
 +/**
 + * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 + */
 +class Product
 +{
 +    /**
 +     * @ORM\Id
 +     * @ORM\GeneratedValue
 +     * @ORM\Column(type="integer")
 +     */
 +    private $id;
 +
 +    /**
 +     * @ORM\Column(type="string", length=100)
 +     */
 +    private $name;
 +
 +    /**
 +     * @ORM\Column(type="decimal", scale=2, nullable=true)
 +     */
 +    private $price;
 +}
 +</sxh>
 +
 +Génération du script de mise à jour :
 +<sxh bash;gutter:false>
 +php bin/console doctrine:migrations:diff
 +</sxh>
 +
 +Exécution des mises à jour :
 +<sxh bash;gutter:false>
 +php bin/console doctrine:migrations:migrate
 +</sxh>
 +
 +===== Génération des classes depuis la base de données =====
 +
 +<sxh bash;gutter:false>
 +php bin/console doctrine:mapping:convert --from-database annotation ./src/Entity
 </sxh> </sxh>
  • framework-web/symfony/models.1517794427.txt.gz
  • Dernière modification : il y a 6 ans
  • (modification externe)