Pages

Symfony et formulaire sujet

mercredi 29 janvier 2014




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:


<?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:


<?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:


<?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




Aucun commentaire:

Enregistrer un commentaire