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 2] Probleme avec gregwar captcha [2.x]


Sujet :

Symfony PHP

  1. #1
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut [Symfony 2] Probleme avec gregwar captcha
    Salut

    Voile j'ai voulu ajouter un captch au formulaire d'inscription du fosuserbundle bien sur j'ai surchargé la classe RegistrationFormType dans mon bundle UserBundle

    J'ai mis ce qu'il faut mettre dans le fichier service de mon bundle UserBundle

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    services:         
        siteweb_user.registration.form.type:
            class: Siteweb\UserBundle\Form\Type\RegistrationFormType
            arguments: [%fos_user.model.user.class%]
            tags:
                - { name: form.type, alias: siteweb_user_registration }
    et dans app/config/config.yml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    fos_user:
        db_driver:     orm                        # Le type de BDD à utiliser, nous utilisons l'ORM Doctrine depuis le début
        firewall_name: main                       # Le nom du firewall duquel on utilisera ces utilisateurs
        user_class:    Siteweb\UserBundle\Entity\User # La classe de l'entité User que nous venons de définir    
        registration:
            form:
                type: siteweb_user_registration
    bref et j'ai suivis ce toto pour installer mon captcha :

    https://github.com/Gregwar/CaptchaBundle

    apres avoir testé j'ai eu cette erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Fatal error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in /var/www/Symfony/vendor/bundles/Gregwar/CaptchaBundle/Type/CaptchaType.php on line 129
    Pouvez vous m'aider svp ?

    Cordialement

  2. #2
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    725
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2011
    Messages : 725
    Points : 1 050
    Points
    1 050
    Par défaut
    la signature de la méthode buildForm a changé entre Symfony2 et Symfony2.1
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    //SF2
    public function buildForm(FormBuilder $builder, array $options);
    //SF2.1
    public function buildForm(FormBuilderInterface $builder, array $options);
    Donc tu utilises sans doute SF2 avec une version du CapchtaBundle destiné à SF2.1 (ou bien l'inverse)
    passes sur la branche 2.0 du CapchtaBundle à la place de master

  3. #3
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    Salut arnoo

    j'ai fais ce que tu m'as dis, j'ai telechargé la captcha 2.0 mais j'ai tjr la méme erreur

    pour info j'utilise symfony 2.0.16

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Fatal error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in /var/www/Symfony/vendor/bundles/Gregwar/CaptchaBundle/Type/CaptchaType.php on line 129
    Cordialement

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2009
    Messages : 135
    Points : 110
    Points
    110
    Par défaut
    bonjour,
    je suis entrain d'utiliser ce bundle et j'ai pas trouvé aucun problème
    il faut que tu télécharge le bundle correspond a la version sf2
    A+

  5. #5
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    725
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2011
    Messages : 725
    Points : 1 050
    Points
    1 050
    Par défaut
    quel est la signature de la méthode buildForm dans Gregwar\CaptchaBundle\Type\CaptchaType dans le répertoire Vendor ?

  6. #6
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    Citation Envoyé par arnooo999 Voir le message
    quel est la signature de la méthode buildForm dans Gregwar\CaptchaBundle\Type\CaptchaType dans le répertoire Vendor ?
    FormTypeInterface.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
    <?php
     
    /*
     * This file is part of the Symfony package.
     *
     * (c) Fabien Potencier <fabien@symfony.com>
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */
     
    namespace Symfony\Component\Form;
     
    interface FormTypeInterface
    {
        /**
         * Builds the form.
         *
         * This method gets called for each type in the hierarchy starting form the
         * top most type.
         * Type extensions can further modify the form.
         *
         * @see FormTypeExtensionInterface::buildForm()
         *
         * @param FormBuilder $builder The form builder
         * @param array       $options The options
         */
        public function buildForm(FormBuilder $builder, array $options);
     
        /**
         * Builds the form view.
         *
         * This method gets called for each type in the hierarchy starting form the
         * top most type.
         * Type extensions can further modify the view.
         *
         * @see FormTypeExtensionInterface::buildView()
         *
         * @param FormView      $view The view
         * @param FormInterface $form The form
         */
        public function buildView(FormView $view, FormInterface $form);
     
        /**
         * Builds the form view.
         *
         * This method gets called for each type in the hierarchy starting form the
         * top most type.
         * Type extensions can further modify the view.
         *
         * Children views have been built when this method gets called so you get
         * a chance to modify them.
         *
         * @see FormTypeExtensionInterface::buildViewBottomUp()
         *
         * @param FormView      $view The view
         * @param FormInterface $form The form
         */
        public function buildViewBottomUp(FormView $view, FormInterface $form);
     
        /**
         * Returns a builder for the current type.
         *
         * The builder is retrieved by going up in the type hierarchy when a type does
         * not provide one.
         *
         * @param string               $name    The name of the builder
         * @param FormFactoryInterface $factory The form factory
         * @param array                $options The options
         *
         * @return FormBuilder|null A form builder or null when the type does not have a builder
         */
        public function createBuilder($name, FormFactoryInterface $factory, array $options);
     
        /**
         * Returns the default options for this type.
         *
         * @param array $options
         *
         * @return array The default options
         */
        public function getDefaultOptions(array $options);
     
        /**
         * Returns the allowed option values for each option (if any).
         *
         * @param array $options
         *
         * @return array The allowed option values
         */
        public function getAllowedOptionValues(array $options);
     
        /**
         * Returns the name of the parent type.
         *
         * @param array $options
         *
         * @return string|null The name of the parent type if any otherwise null
         */
        public function getParent(array $options);
     
        /**
         * Returns the name of this type.
         *
         * @return string The name of this type
         */
        public function getName();
     
        /**
         * Adds extensions for this type.
         *
         * @param array $extensions An array of FormTypeExtensionInterface
         *
         * @throws UnexpectedTypeException if any extension does not implement FormTypeExtensionInterface
         */
        public function setExtensions(array $extensions);
     
        /**
         * Returns the extensions associated with this type.
         *
         * @return array An array of FormTypeExtensionInterface
         */
        public function getExtensions();
    }
    CaptchaType.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
    <?php
     
    namespace Gregwar\CaptchaBundle\Type;
     
    use Symfony\Component\HttpFoundation\Session\Session;
    use Symfony\Component\DependencyInjection\ContainerInterface;
     
    use Symfony\Component\Form\FormView;
    use Symfony\Component\Form\FormInterface;
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\Exception\FormException;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
    use Symfony\Component\Form\FormViewInterface;
     
    use Gregwar\CaptchaBundle\Validator\CaptchaValidator;
    use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
    use Gregwar\CaptchaBundle\DataTransformer\EmptyTransformer;
     
    /**
     * Captcha type
     *
     * @author Gregwar <g.passault@gmail.com>
     */
    class CaptchaType extends AbstractType
    {
        /**
         * Options
         * @var array
         */
        private $options = array();
     
        /**
         * Session key
         * @var string
         */
        private $key = 'captcha';
     
        public function __construct(Session $session, $config)
        {
            $this->session = $session;
            $this->options = $config;
        }
     
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $this->key = $builder->getForm()->getName();
     
            $builder->addValidator(
                new CaptchaValidator($this->session,
                                     $this->key,
                                     $options['invalid_message'],
                                     $options['bypass_code'])
            );
        }
     
        public function buildView(FormView $view, FormInterface $form, array $options)
        {
            $fingerprint = null;
     
            if ($options['keep_value'] && $this->session->has($this->key.'_fingerprint')) {
                $fingerprint = $this->session->get($this->key.'_fingerprint');
            }
     
            $generator = new CaptchaGenerator($this->generateCaptchaValue(),
                                              $options['image_folder'],
                                              $options['web_path'],
                                              $options['gc_freq'],
                                              $options['expiration'],
                                              $options['font'],
                                              $fingerprint,
                                              $options['quality']);
     
            if ($options['as_file']) {
                $captchaCode = $generator->getFile($options['width'], $options['height']);
            } else {
                $captchaCode = $generator->getCode($options['width'], $options['height']);
            }
     
            if ($options['keep_value']) {
                $this->session->set($this->key.'_fingerprint', $generator->getFingerprint());
            }
     
            $fieldVars = array(
                'captcha_width'     => $options['width'],
                'captcha_height'    => $options['height'],
                'captcha_code'      => $captchaCode,
                'value'             => '',
            );
     
            foreach($fieldVars as $name => $value){
                $view->set($name,$value);    
            }
        }
     
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $this->options['property_path'] = false;
            $resolver->setDefaults($this->options);
        }
     
        public function getParent()
        {
            return 'text';
        }
     
        public function getName()
        {
            return 'captcha';
        }
     
        private function generateCaptchaValue()
        {
            if (!$this->options['keep_value'] || !$this->session->has($this->key)) {
                $value = '';
                $chars = str_split($this->options['charset']);
     
                for ($i=0; $i<$this->options['length']; $i++) {
                    $value.= $chars[array_rand($chars)];
                }
     
                $this->session->set($this->key, $value);
            } else {
                $value = $this->session->get($this->key);
            }
     
            return $value;
        }
    }

  7. #7
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    725
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2011
    Messages : 725
    Points : 1 050
    Points
    1 050
    Par défaut
    tu as téléchargé la version "master"

    compare les signatures des méthodes
    master : (pour SF 2.1)
    https://github.com/Gregwar/CaptchaBu...aptchaType.php
    2.0 : (pour SF2)
    https://github.com/Gregwar/CaptchaBu...aptchaType.php

  8. #8
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    j'ai éssayé la version 2.0 de captcha gregwar pour symfony 2.0.16 vu que c la version que j'ai en ce moment mais rien j'ai tjrs la méme erreur

    j'ai éssayé de le télécharger par commande :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    git submodule add git://github.com/Gregwar/CaptchaBundle.git vendor/bundles/Gregwar/CaptchaBundle
    mais j'ai eu cette erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fatal:Not a git repository (or any of the parent directories): .git
    j'ai mis ça dans le fichier deps:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    GregwarCaptchaBundle]
            git=git://github.com/Gregwar/CaptchaBundle.git
            target=/bundles/Gregwar/CaptchaBundle
            version=origin/2.0
    Cordialement

  9. #9
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    725
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2011
    Messages : 725
    Points : 1 050
    Points
    1 050
    Par défaut
    j'ai mis ça dans le fichier deps:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    [GregwarCaptchaBundle]
            git=git://github.com/Gregwar/CaptchaBundle.git
            target=/bundles/Gregwar/CaptchaBundle
            version=origin/2.0
    normalement il suffit de faire:
    php bin/vendors install

    si c'est toujours la mauvaise version
    1. supprime la section gregwarCapchtaBundle dans le fichier deps.lock
    2. supprime le répertoire vendor/bundles/Gregwar/CaptchaBundle
    3. relance php bin/vendors install

  10. #10
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    c bon j'ai fais ce que tu m'as dis

    maintenant j'ai cette erreur la

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Expected argument of type "FOS\UserBundle\Form\Model\CheckPassword", "Siteweb\UserBundle\Entity\User" given

  11. #11
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    Up

  12. #12
    Membre du Club
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Avril 2011
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2011
    Messages : 139
    Points : 65
    Points
    65
    Par défaut
    c bon g trouvé la solution j'avais une erreur syntaxique dans mon fichier registrationformtype.php

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 01/10/2012, 18h55
  2. [1.x] probleme avec les commandes de symfony 1.4.2
    Par hermess777 dans le forum Symfony
    Réponses: 8
    Dernier message: 28/10/2011, 15h55
  3. [1.x] Probleme avec les EmbeddedForms symfony
    Par ODriginal dans le forum Symfony
    Réponses: 3
    Dernier message: 18/08/2011, 09h24
  4. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

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