Bonjours à tous, je suis en train de construire un site avec symfony, seulement voila j'ai un bug à l'enregistrement de mes membres.
Pour gérer mes membres j'utilise le plugin sfDoctrineGuardPlugin, que j'ai adapter pour mes besoins grave au tuto suivant:
http://www.symfony-project.org/blog/...ineguardplugin
Puis une inscription via le tuto:
http://www.symfony-project.org/blog/...ineguardplugin
Seulement voila à l'enregistrement, j'ai 2 enregistrement identique dans ma table profile 1 avec le champs en relation avec sf_guard_user rempli et correct et 1 ou le champs et vide.
Voila mes codes:
frontend/modules/register/actions/actions.class.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 Profile: columns: nom: { type: string(255) } prenom: { type: string(255) } user_id: { type: integer(4), notnull: true, unique: true } email: { type: string(255), notnull: true } msn: { type: string(255) } site: { type: string(255) } anniversaire: { type: date } promo: { type: string(255) } sexe: { type: integer(1) } signature: { type: string(4000) } nb_post: { type: integer, notnull: true, default: 0 } nb_roneo: { type: integer, notnull: true, default: 0 } avatar: { type: string(255) } infos: { type: string(4000) } relations: sfGuardUser: { local: user_id, foreign: id, onDelete: cascade }
frontend/modules/register/lib/RegisterForm.class.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 <?php class registerActions extends sfActions { /** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new RegisterForm(); //vérification du formulaire. if($request->isMethod('post')) { $this->form->bind($request->getParameter($this->form->getName())); if($this->form->isValid()) { $this->form->save(); } } } } ?>
frontend/modules/register/templates/indexSuccess.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 <?php class RegisterForm extends sfGuardUserForm { public function configure() { //Inclusion des définitions dans la classe parente. parent::configure(); //Suppression des champs définit automatiquement. unset( $this['is_active'], $this['is_super_admin'], $this['updated_at'], $this['created_at'], $this['algorithm'], $this['salt'], $this['last_login'], $this['groups_list'], $this['permissions_list'] ); $this->widgetSchema->setLabel('username', 'Login'); $this->widgetSchema->setLabel('password', 'Mot de passe'); $profileForm = new ProfileForm(); //Suppression des champs définit automatiquement de ProfileForm unset( $profileForm['user_id'], $profileForm['nb_post'], $profileForm['nb_roneo'], $profileForm['id'], $profileForm['avatar'] ); $this->embedForm('Profile', $profileForm); } } ?>
lib/form/doctrine/ProfileForm.class.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <h1>Inscription</h1> <?php echo $form->renderFormTag(url_for('register/index')) ?> <table> <?php echo $form ?> </table> <input type="submit" name="register" value="S'inscrire" /> </form>
lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.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 class ProfileForm extends BaseProfileForm { public function configure() { //Variables spécifiques du formulaire. $years = range(1940, 2020); //Définition des règles des champs. $this->widgetSchema['promo'] = new sfWidgetFormChoice(array('choices' => Doctrine::getTable('Profile')->getPromos(), 'expanded' => false, 'multiple' => false )); $this->widgetSchema['sexe'] = new sfWidgetFormChoice(array('choices' => Doctrine::getTable('Profile')->getSexes(), 'expanded' => true, 'multiple' => false )); $this->widgetSchema['anniversaire'] = new sfWidgetFormDate(array( 'format' => '%day% - %month% - %year%', 'years' => array_combine($years, $years) ) ); $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden(); //Définition des règles de validations. $this->validatorSchema['email'] = new sfValidatorEmail(); $this->validatorSchema['msn'] = new sfValidatorEmail(array('required' => false)); $this->validatorSchema['site'] = new sfValidatorUrl(array('required' => false)); $this->validatorSchema['anniversaire'] = new sfValidatorDate(); $this->validatorSchema['promo'] = new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Profile')->getPromos()))); $this->validatorSchema['sexe'] = new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Profile')->getSexes()))); $this->validatorSchema['user_id'] = new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'column' => 'id', 'required' => false)); //Définition des labels des champs. $this->widgetSchema->setLabels(array( 'nom' => 'Nom', 'prenom' => 'Prénom', 'email' => 'Adresse E-mail', 'site' => 'Site Web', 'anniversaire' => 'Date de naissance', 'promo' => 'Filière/Promo', 'infos' => 'Biographie' )); } }
Voila si jamais quelqu'un a la solution, je suis prenneur.
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 class sfGuardUserForm extends PluginsfGuardUserForm { public function configure() { $this->widgetSchema['password'] = new sfWidgetFormInputPassword(); //Ajout du champs de confirmation du mot de passe. $this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword(); //Règles de validations. $this->validatorSchema['password']->setOption('required', true); $this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password']; $this->mergePostValidator(new sfValidatorSchemaCompare('password', '==', 'password_confirmation',array(),array('invalid' => 'Les 2 mots de passes doivent correspondre !'))); //Labels. $this->widgetSchema->setLabel('password_confirmation', 'Confirmez votre mot de passe'); //Placement. $this->widgetSchema->moveField('password_confirmation', 'after','password'); } }
Merci d'avance
-abL^
Partager