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 :

Validation form fonctionne partiellement


Sujet :

Symfony PHP

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2013
    Messages : 54
    Points : 27
    Points
    27
    Par défaut Validation form fonctionne partiellement
    Bonjour,

    J'utilise les Assert dans mes entitées pour valider mes formulaire.
    En gros j'ai une application qui as un nom, et qui imbrique un logo (image) en relation OnetoOne.

    Mon souci:
    J'ai bien la validation qui fonctionne pour le nombre de caractère minimum pour le nom de l'application (2) mais elle ne fontionne pas pour le type de Logo (jpg, png) ainsi que la taille (1024k).
    Je peux par exemple uploader une fichier rar de 50Mo.

    Sauriez vous me dire d'ou vient le problème?


    Voici mes fichiers:


    Application.php
    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
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    <?php
     
    namespace GoSoft\MainBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
     
     
    /**
     * GoSoft\MainBundle\Entity\Application
     *
     * @ORM\Table(name="applications")
     * @ORM\HasLifecycleCallbacks
     * @ORM\Entity(repositoryClass="GoSoft\MainBundle\Entity\ApplicationRepository")
     */
    class Application
    {
        /**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var string $nom
         *
         * @ORM\Column(name="nom", type="string", length=255)
         * @Assert\MinLength(limit = 2)
         */
    	 //@Assert\MinLength(limit = 2, message = "Le nom de famille doit avoir au moins {{ limit }} caractères")
        private $nom;
     
    	/**
    	 * @ORM\ManyToOne(targetEntity="GoSoft\UserBundle\Entity\User")
         * @ORM\JoinColumn(nullable=false)
    	 * @Assert\Type(type="GoSoft\UserBundle\Entity\User")
    	 */
    	private $user;
     
        /**
         * @var text $description
         *
         * @ORM\Column(name="description", type="text")
         * @Assert\NotBlank()
         */
        private $description;
     
    	/**
         * @var decimal $note
         *
         * @ORM\Column(name="note", type="decimal", scale=2, nullable=true)
         */
        private $note;
     
    	/**
         * @var decimal $prix
         *
         * @ORM\Column(name="prix", type="decimal", scale=2)
         * @Assert\NotBlank()
         */
        private $prix;
     
    	/**
         * @var decimal $prix_promo
         *
         * @ORM\Column(name="prix_promo", type="decimal", scale=2, nullable=true)
         */
        private $prix_promo;
     
    	/**
         * @var datetime $date_ajout
         *
         * @ORM\Column(name="date_ajout", type="datetime")
         * @Assert\DateTime()
         */
        private $date_ajout;
     
    	/**
         * @var datetime $date_maj
         *
         * @ORM\Column(name="date_maj", type="datetime", nullable=true)
         */
        private $date_maj;
     
    	/**
         * @var string $ageMinimum
         *
         * @ORM\Column(name="age_minimum", type="integer", nullable=true)
         */
        private $ageMinimum;
     
        /**
    	 * @var boolean $publication
         * @ORM\Column(name="publication", type="boolean")
         */
        private $publication;
     
    	/**
         * @ORM\ManyToOne(targetEntity="GoSoft\MainBundle\Entity\Categorie")
         * @ORM\JoinColumn(nullable=false)
         */
        private $categorie;
     
    	/**
         * @ORM\OneToOne(targetEntity="GoSoft\MainBundle\Entity\Logo", cascade={"persist"})
         */
    	private $logo;
     
     
    	/**
    	 * @ORM\OneToMany(targetEntity="GoSoft\MainBundle\Entity\Capture", mappedBy="application", cascade={"persist"})
    	 */
    	private $captures;
     
    	/**
         * @var string $video
         *
         * @ORM\Column(name="video", type="string", length=255, nullable=true)
         */
        private $video;
     
    	/**
    	 * @ORM\OneToMany(targetEntity="GoSoft\MainBundle\Entity\Fichier", mappedBy="application", cascade={"persist"})
    	 */
    	private $fichiers;
     
    	/**
    	 * @ORM\OneToMany(targetEntity="GoSoft\MainBundle\Entity\Avis", mappedBy="application")
    	 */
    	private $avis;
     
     
    	public function __construct()
        {
    		$this->date_ajout   = new \Datetime;
            $this->publication  = false;
    		$this->captures = new \Doctrine\Common\Collections\ArrayCollection();
    		$this->fichiers = new \Doctrine\Common\Collections\ArrayCollection();
    		$this->avis = new \Doctrine\Common\Collections\ArrayCollection();
    	}
     
     
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         * @return Application
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
     
            return $this;
        }
     
        /**
         * Get nom
         *
         * @return string 
         */
        public function getNom()
        {
            return $this->nom;
        }
     
        /**
         * Set description
         *
         * @param string $description
         * @return Application
         */
        public function setDescription($description)
        {
            $this->description = $description;
     
            return $this;
        }
     
        /**
         * Get description
         *
         * @return string 
         */
        public function getDescription()
        {
            return $this->description;
        }
     
        /**
         * Set prix
         *
         * @param float $prix
         * @return GoSoftApplication
         */
        public function setPrix($prix)
        {
            $this->prix = $prix;
     
            return $this;
        }
     
        /**
         * Get prix
         *
         * @return float 
         */
        public function getPrix()
        {
            return $this->prix;
        }
     
        /**
         * Set publication
         *
         * @param boolean $publication
         * @return Application
         */
        public function setPublication($publication)
        {
            $this->publication = $publication;
     
            return $this;
        }
     
        /**
         * Get publication
         *
         * @return boolean 
         */
        public function getPublication()
        {
            return $this->publication;
        }
     
        /**
         * Set categorie
         *
         * @param GoSoft\MainBundle\Entity\GoSoftCategorie $categorie
         * @return GoSoftApplication
         */
        public function setCategorie(\GoSoft\MainBundle\Entity\Categorie $categorie)
        {
            $this->categorie = $categorie;
     
            return $this;
        }
     
        /**
         * Get categorie
         *
         * @return GoSoft\MainBundle\Entity\GoSoftCategorie 
         */
        public function getCategorie()
        {
            return $this->categorie;
        }
     
        /**
         * Set prix_promo
         *
         * @param float $prixPromo
         * @return Application
         */
        public function setPrixPromo($prixPromo)
        {
            $this->prix_promo = $prixPromo;
     
            return $this;
        }
     
        /**
         * Get prix_promo
         *
         * @return float 
         */
        public function getPrixPromo()
        {
            return $this->prix_promo;
        }
     
        /**
         * Set user
         *
         * @param GoSoft\UserBundle\Entity\User $user
         * @return Application
         */
        public function setUser(\GoSoft\UserBundle\Entity\User $user)
        {
            $this->user = $user;
     
            return $this;
        }
     
        /**
         * Get user
         *
         * @return GoSoft\UserBundle\Entity\User 
         */
        public function getUser()
        {
            return $this->user;
        }
     
        /**
         * Set date_ajout
         *
         * @param \DateTime $dateAjout
         * @return Application
         */
        public function setDateAjout($dateAjout)
        {
            $this->date_ajout = $dateAjout;
     
            return $this;
        }
     
        /**
         * Get date_ajout
         *
         * @return \DateTime 
         */
        public function getDateAjout()
        {
            return $this->date_ajout;
        }
     
        /**
         * Set date_maj
         *
         * @param \DateTime $dateMaj
         * @return Application
         */
        public function setDateMaj($dateMaj)
        {
            $this->date_maj = $dateMaj;
     
            return $this;
        }
     
        /**
         * Get date_maj
         *
         * @return \DateTime 
         */
        public function getDateMaj()
        {
            return $this->date_maj;
        }
     
     
     
        /**
         * Set note
         *
         * @param float $note
         * @return Application
         */
        public function setNote($note)
        {
            $this->note = $note;
     
            return $this;
        }
     
        /**
         * Get note
         *
         * @return float 
         */
        public function getNote()
        {
            return $this->note;
        }
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Avis $avi
    	 * @return Application
    	 */
    	public function addAvi(\GoSoft\MainBundle\Entity\Avis $av)
    	{
    		$this->avis[] = $avi;
    		return $this;
    	}
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Avis $avi
    	 */
    	public function removeAvi(\GoSoft\MainBundle\Entity\Avis $avi)
    	{
    		$this->commentaires->removeElement($commentaire);
    	}
     
    	/**
    	 * @return Doctrine\Common\Collections\Collection
    	 */
    	public function getAvis()
    	{
    		return $this->avis;
    	}
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Logo $logo
    	 * @return Application
    	 */
    	public function setLogo(\GoSoft\MainBundle\Entity\Logo $logo = null)
    	{
    		$this->logo = $logo;
    		return $this;
    	}
     
    	/**
    	* @return GoSoft\MainBundle\Entity\Logo
    	*/
    	public function getLogo()
    	{
    		return $this->logo;
    	}
     
        /**
         * Set ageMinimum
         *
         * @param integer $ageMinimum
         * @return Application
         */
        public function setAgeMinimum($ageMinimum)
        {
            $this->ageMinimum = $ageMinimum;
     
            return $this;
        }
     
        /**
         * Get ageMinimum
         *
         * @return integer 
         */
        public function getAgeMinimum()
        {
            return $this->ageMinimum;
        }
     
     
     
     
     
     
     
        /**
    	 * @param GoSoft\MainBundle\Entity\Capture $capture
    	 * @return Application
    	 */
    	public function addCapture(\GoSoft\MainBundle\Entity\Capture $capture)
    	{
    		$this->captures[] = $capture;
    		return $this;
    	}
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Capture $capture
    	 */
    	public function removeCapture(\GoSoft\MainBundle\Entity\Capture $capture)
    	{
    		$this->captures->removeElement($capture);
    	}
     
    	/**
    	* @return Doctrine\Common\Collections\Collection
    	*/
    	public function getCaptures()
    	{
    		return $this->captures;
    	}
     
    	/**
         * Set video
         *
         * @param string $video
         * @return Application
         */
        public function setVideo($video)
        {
            $this->video = $video;
     
            return $this;
        }
     
        /**
         * Get video
         *
         * @return string 
         */
        public function getVideo()
        {
            return $this->video;
        }
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Fichier $fichier
    	 * @return Application
    	 */
    	public function addFichier(\GoSoft\MainBundle\Entity\Fichier $fichier)
    	{
    		$this->fichiers[] = $fichier;
    		return $this;
    	}
     
    	/**
    	 * @param GoSoft\MainBundle\Entity\Fichier $fichier
    	 */
    	public function removeFichier(\GoSoft\MainBundle\Entity\Fichier $fichier)
    	{
    		$this->fichiers->removeElement($fichier);
    	}
     
    	/**
    	* @return Doctrine\Common\Collections\Collection
    	*/
    	public function getFichiers()
    	{
    		return $this->fichiers;
    	}
    }
    Logo.php
    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
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    <?php
     
    namespace GoSoft\MainBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
    use Symfony\Component\HttpFoundation\File\File;
     
    /**
     * GoSoft\MainBundle\Entity\Application
     *
     * @ORM\Table(name="logos")
     * @ORM\HasLifecycleCallbacks
     * @ORM\Entity(repositoryClass="GoSoft\MainBundle\Entity\LogoRepository")
     */
    class Logo
    {
        /**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
    	/**
    	 * @var string $image
    	 * @ORM\Column(name="image", type="string", length=255)
    	 */
    	private $image;
     
    	/**
    	 * @var string $modification
    	 * @ORM\Column(name="modification", type="integer")
    	 */
    	private $modification;
     
    	/**
    	 * @var object $objFile
    	 * @Assert\File(
         *     maxSize = "1024k",
         *     mimeTypes = {"image/jpeg", "image/png"},
         *     mimeTypesMessage = "Veuillez uploader une image valide"
         * )*/
    	private $objFile;
     
     
    	public function __construct()
        {
    		$this->image = "no_image.jpg";
    		$this->modification = 0;
    	}
     
     
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
     
     
        /**
         * Set image
         *
         * @param string $image
         * @return logo
         */
        public function setImage($image)
        {
            $this->image = $image;
     
            return $this;
        }
     
        /**
         * Get image
         *
         * @return string 
         */
        public function getImage()
        {
            return $this->image;
        }
     
    	/**
    	 * Set objFile
    	 *
    	 * @param object $objFile
    	 * @return Application
    	 */
    	public function setObjFile(File $objFile = null)
    	{
    	    $this->objFile = $objFile;
     
    	    return $this;
    	}
     
    	/**
    	 * Get objFile
    	 *
    	 * @return object 
    	 */
    	public function getObjFile()
    	{
    	    return $this->objFile;
    	}
     
     
     
     
     
        /**
         * @ORM\PrePersist()
         * @ORM\PreUpdate()
         */
        public function preUpload()
        {
    		// Si le champ d'upload est vide on ne fait rien
            if (null === $this->objFile) {
    			return;
            }
    		// Si on ajoute un logo et que l'appli avait déjà un logo (update)
            elseif (null !== $this->objFile && $this->image !== "no_image.jpg") {
    			unlink($this->getUploadRootDir().$this->image);
                $this->image = $this->objFile->getClientOriginalName();
            }
    		// Si on ajoute un logo et que l'appli n'avait pas de logo
    		elseif (null !== $this->objFile && $this->image === "no_image.jpg") {
                $this->image = $this->objFile->getClientOriginalName();
            }
        }
     
        /**
         * @ORM\PostPersist()
         * @ORM\PostUpdate()
         */
        public function upload()
        {
            if (null === $this->objFile) {
                return;
            }
     
    		if(!is_dir($this->getUploadRootDir())){
    			mkdir($this->getUploadRootDir());
            }
     
            // vous devez lancer une exception ici si le fichier ne peut pas
            // être déplacé afin que l'entité ne soit pas persistée dans la
            // base de données comme le fait la méthode move() de UploadedFile
            $this->objFile->move($this->getUploadRootDir(), $this->image);
            unset($this->objFile);
        }
     
     
    	// propriété utilisé temporairement pour la suppression
        private $filenameForRemove;
     
        /**
         * @ORM\PreRemove()
         */
        public function storeFilenameForRemove()
        {
            $this->filenameForRemove = $this->getUploadRootDir().$this->image;
        }
     
        /**
         * @ORM\PostRemove()
         */
        public function removeUpload()
        {
            if ($this->filenameForRemove && $this->image != "no_image.jpg") {
                unlink($this->filenameForRemove);
    			rmdir($this->filenameForRemove.'/..');
            }
        }
     
     
     
        protected function getUploadRootDir()
        {
            // le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
            return __DIR__.'/../../../../web/'.$this->getUploadDir();
        }
     
        protected function getUploadDir()
        {
            // on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
            // le document/image dans la vue.
            return 'upload/logo/'.$this->getId().'/';
        }
     
        /**
         * Set modification
         *
         * @param integer $modification
         * @return Logo
         */
        public function setModification($modification)
        {
            $this->modification = $modification;
     
            return $this;
        }
     
        /**
         * Get modification
         *
         * @return integer 
         */
        public function getModification()
        {
            return $this->modification;
        }
    }
    ApplicationModLogoType.php
    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
    <?php
     
    namespace GoSoft\MainBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
     
    class ApplicationModLogoType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
    			->add('logo', new LogoType)
            ;
        }
     
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'GoSoft\MainBundle\Entity\Application'
            ));
        }
     
        public function getName()
        {
            return 'gosoft_mainbundle_applicationmodlogotype';
        }
    }

    LogoType.php
    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
    <?php
     
    namespace GoSoft\MainBundle\Form;
     
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
     
    class LogoType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
                ->add('objFile', 'file', array('label'  => 'Logo', 'required' => false))
            ;
        }
     
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'GoSoft\MainBundle\Entity\Logo'
            ));
        }
     
        public function getName()
        {
            return 'gosoft_mainbundle_logotype';
        }
    }

  2. #2
    Membre à l'essai
    Inscrit en
    Février 2010
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 32
    Points : 22
    Points
    22
    Par défaut
    bonjour, je ne suis pas expert mais ton assert est sur objfile. et pas sur logo.

    je ne comprends pas pourquoi il y a un private logo et un objfile.

    C'est peut être une piste?

    Bonne chance

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2013
    Messages : 54
    Points : 27
    Points
    27
    Par défaut
    Bonjour,

    - objfile est mon fichier uploadé (pas enregistré en bdd)
    - logo est le nom du fichier uploadé (sauvegardé en bdd, par exemple: "image.jpg")

    J'ai essayé de sauvegarder en base de donnée le objfile mais les assert ne fonctionnent toujours pas pour le objfile.

  4. #4
    Membre expérimenté Avatar de Nico_F
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 728
    Points : 1 310
    Points
    1 310
    Par défaut
    If the file you're validating is an image, try the Image constraint.

    Source : http://symfony.com/doc/current/refer...ints/File.html
    Commence déja par ça : Assert\Image.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2013
    Messages : 54
    Points : 27
    Points
    27
    Par défaut
    J'ai exactement le même soucis avec Image.
    ps: Image une classe qui se base sur File.

  6. #6
    Membre expérimenté Avatar de Nico_F
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 728
    Points : 1 310
    Points
    1 310
    Par défaut
    La contrainte maxSize passe toujours si le fichier que tu essayes d'uploader est plus gros que la valeur upload_max_filesize configuré dans ton php.ini.

    Il serait peut-être plus prudent de passer par une méthode callback dans laquelle tu vérifies toi même les éléments que tu ne souhaites pas laisser passer.

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2013
    Messages : 54
    Points : 27
    Points
    27
    Par défaut
    Effectivement j'ai eu un soucis au début car la valeur du php.ini etait très faible.

    Symfony renvoyait bien une erreur que le fichier était trop gros pour PHP.
    C'est tout de même incompréhensible que les Assert ne fonctionne pas.


    ps: je met mes sources simplifiées au minimum à disposition si ca peut aider à trouver l'origine de l'erreur.
    Fichiers attachés Fichiers attachés

  8. #8
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2013
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2013
    Messages : 54
    Points : 27
    Points
    27
    Par défaut
    Bon alors j'ai testé en appelant directement le formulaire Logo et la les assert fonctionnent.

    Il faut croire que les assert ne fonctionnent pas si c'est un formulaire imbriqué dans un formulaire.

    Ou alors j'ai raté quelque chose.


    Connaitriez vous une méthode pour valider les données d'un formulaire incorporé dans un autre?

    Ici j'ai le ApplicationType qui appelle le LogoType et du coup les assert de l'entité Logo ne sont pas prises en compte.



    EDIT: J'ai trouvé la cause:
    Dans le formulaire principale il faut avoir 'cascade_validation' => true pour faire remonter les erreurs des formulaire imbriqués au formulaire père.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'Acme\Bundle\AcmeBundle\Entity\MyEntity',
                'cascade_validation' => true
            ));
        }

  9. #9
    Membre expérimenté Avatar de Nico_F
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 728
    Points : 1 310
    Points
    1 310
    Par défaut
    Je rajouterai également que si tu utilises les groupes de validation, et que tu souhaites valider des formulaires embarqués (collection etc.), il faut que les règles de validation reçoivent le groupe du formulaire parent, et pas celui des formulaires se trouvant dans la collection.

    Un formulaire formA basé sur une entité A embarque une collection de formB basé sur une entité B. Dans les annotations de B, il faudra désigner le groupe de validation du formA pour valider les éléments de B et non celui du formB pour que ceux-ci soient effectifs.

  10. #10
    Membre éclairé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Août 2011
    Messages
    477
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Août 2011
    Messages : 477
    Points : 677
    Points
    677
    Par défaut
    Merci Nico, pour cette précision utile. Je pense que l'on peux bien galéré la dessus.

Discussions similaires

  1. [AJAX] [validate form] remote ne semble pas fonctionner
    Par beegees dans le forum jQuery
    Réponses: 6
    Dernier message: 07/08/2013, 15h41
  2. Réponses: 2
    Dernier message: 06/04/2012, 14h49
  3. Validation Form Principal
    Par xanthos1348 dans le forum Access
    Réponses: 5
    Dernier message: 26/02/2006, 21h44
  4. validation form en fonction de plusieurs groupe de checkbox
    Par Steph777 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 09/01/2006, 12h00
  5. [Struts] Validate Form et ActionError
    Par cosmos38240 dans le forum Struts 1
    Réponses: 4
    Dernier message: 25/10/2005, 16h00

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