IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Symfony et formulaire


Sujet :

Symfony PHP

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    développeur en alternance
    Inscrit en
    Juillet 2013
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : développeur en alternance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2013
    Messages : 1
    Par défaut Symfony et formulaire
    Bonjour,
    je suis actuellement sur un projet avec symfony, je dois créer un bundle qui permet d'enregistrer un produit d'un concurrent pour comparer son prix,je bloque sur le formulaire, mon formulaire est présenté de cette manière :

    Nom : (nom du produit sur ma boutique)
    Ref : (ref du produit de ma boutique)
    Url du produit : (Url du produit concurrent)
    Type: (categorie du produit)
    Script : (choix du script a executer pour ce produit celon le concurrent)

    le soucis est que si j'ai les deux meme produit chez deux concurrents ou plus je peux mettre qu'une url est il possible d'avoir un ajout automatique d'une colonne dans la base de donnée ainsi qu'un input url_nom du concurrent sans devoir à chaque fois retoucher le code mais entitées sont faite comme ceci :

    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    <?php
    namespace noza\concurrentBundle\Entity;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
     
    /**
     * @ORM\Entity
     */
     class Produit
     {
    	 /**
    	 * @ORM\GeneratedValue
         * @ORM\Id
         * @ORM\Column(type="integer")
         */
    	 private $id;
     
    	 /**     
    	* @ORM\Column(type="string",length=255)
    	* @Assert\NotBlank()
    	*/
    	private $nom;
     
    	 /**
    	 *@ORM\JoinTable(name="produit_type")
    	 * @ORM\ManyToOne(targetEntity="Type")
         */    
    	 private $type;
     
    	 /**
         * @ORM\Column(type="string",length=14)
         */
    	 private $refdivalto;
     
    	 /**
    	 *@ORM\JoinTable(name="produit_script")
         * @ORM\ManyToOne(targetEntity="Script")
         */
    	 private $script;
     
    	  /**
         * @ORM\Column(type="string",length=255)
         */
    	 private $url_produit;
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         * @return Produit
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
     
            return $this;
        }
     
        /**
         * Get nom
         *
         * @return string 
         */
        public function getNom()
        {
            return $this->nom;
        }
     
        /**
         * Set refdivalto
         *
         * @param string $refdivalto
         * @return Produit
         */
        public function setRefdivalto($refdivalto)
        {
            $this->refdivalto = $refdivalto;
     
            return $this;
        }
     
        /**
         * Get refdivalto
         *
         * @return string 
         */
        public function getRefdivalto()
        {
            return $this->refdivalto;
        }
     
        /**
         * Set url_produit
         *
         * @param string $urlProduit
         * @return Produit
         */
        public function setUrlProduit($urlProduit)
        {
            $this->url_produit = $urlProduit;
     
            return $this;
        }
     
        /**
         * Get url_produit
         *
         * @return string 
         */
        public function getUrlProduit()
        {
            return $this->url_produit;
        }
     
        /**
         * Set type
         *
         * @param \noza\concurrentBundle\Entity\Type $type
         * @return Produit
         */
        public function setType(\noza\concurrentBundle\Entity\Type $type = null)
        {
            $this->type = $type;
     
            return $this;
        }
     
        /**
         * Get type
         *
         * @return \noza\concurrentBundle\Entity\Type 
         */
        public function getType()
        {
            return $this->type;
        }
     
        /**
         * Set script
         *
         * @param \noza\concurrentBundle\Entity\Script $script
         * @return Produit
         */
        public function setScript(\noza\concurrentBundle\Entity\Script $script = null)
        {
            $this->script = $script;
     
            return $this;
        }
     
        /**
         * Get script
         *
         * @return \noza\concurrentBundle\Entity\Script 
         */
        public function getScript()
        {
            return $this->script;
        }
    }

    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
     
    <?php
    namespace noza\concurrentBundle\Entity;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
     
    /**
    * @ORM\Entity
    */
    class Script
    {
    	/**
    	* @ORM\GeneratedValue
    	* @ORM\Id
    	* @ORM\Column(type="integer")
    	*/	
    	private $id;
     
    	/**     
    	* @ORM\Column(type="string",length=255)
    	* @Assert\NotBlank()
    	*/
    	private $nom;
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         * @return Script
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
     
            return $this;
        }
     
        /**
         * Get nom
         *
         * @return string 
         */
        public function getNom()
        {
            return $this->nom;
        }
    }

    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
     
    <?php
    namespace noza\concurrentBundle\Entity;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
     
    /**
     * @ORM\Entity
     */
     class Type
     {
    	/**
    	 * @ORM\GeneratedValue
         * @ORM\Id
         * @ORM\Column(type="integer")
         */
    	 private $id;
     
    	 /**
         * @ORM\Column(type="string",length=255)
         * @Assert\NotBlank()
         */    
    	 private $nom;
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         * @return Type
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
     
            return $this;
        }
     
        /**
         * Get nom
         *
         * @return string 
         */
        public function getNom()
        {
            return $this->nom;
        }
    }
    il faut imaginé que script n'existe plus et que dans mon formulaire il y ai url_nomconcurent1 et par magie si il y a une nouveau concurrent dans la base de donnée concurrent un input url_concurrent2 apparraisse

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2009
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2009
    Messages : 875
    Par défaut
    Le form builder est dynamique, tu cherches a faire quelque chose comme ca non?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    //From/produitType.php
    foreach($urls_concurent as $id_concurent => $url_concurent) {
      $formBuilder->add('url_concurent_'.$id_concurent)
    }

Discussions similaires

  1. [2.x] [Symfony 2] Formulaires et Heritage
    Par REF26 dans le forum Symfony
    Réponses: 2
    Dernier message: 14/02/2014, 16h33
  2. [2.x] [Symfony 2] Formulaire et choice non mapper
    Par REF26 dans le forum Symfony
    Réponses: 2
    Dernier message: 21/01/2014, 12h22
  3. [2.x] [Symfony 2] Formulaire imbriqué + Check & combobox
    Par REF26 dans le forum Symfony
    Réponses: 1
    Dernier message: 19/12/2013, 13h56
  4. [Symfony 2] Formulaire qui affiche une erreur
    Par Ownview dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 17/06/2013, 14h04
  5. [2.x] [Symfony 2] Formulaire type sondage
    Par SempreD dans le forum Symfony
    Réponses: 0
    Dernier message: 30/05/2012, 23h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo