Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > symfony
symfony Forum d'entraide sur le framework PHP symfony. Avant de poster : cours symfony et FAQ symfony
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 06/03/2011, 21h15   #1
Invité de passage
 
Inscription : novembre 2002
Messages : 2
Détails du profil
Informations forums :
Inscription : novembre 2002
Messages : 2
Points : 0
Points : 0
Par défaut Problème backend + i18n

Bonjour,

Je rencontre un problème sur un module qui ne fonctionne pas avec le générateur de backend symfony.

J'ai une table FAQ qui contient quelques champs dont question et answer. J'ai souhaité internationaliser ces 2 champs. Jusque là tout va bien.

Le frontend marche bien mais dans le backend les champs "question" et "answer" apparaissent 3 fois dans mes formulaires d'ajout et de modif : 1 fois en non internationalisé, 1 fois en anglais et 1 fois en français. Normalement le mode non internationalisé ne devrait plus apparaitre. De surcroit, l'ajout et la modif ne fonctionnent pas dans l'admin.

Toutes mes autres modules fonctionnent trés bien avec I18N sauf celui-ci et c'est incompréhensible pour moi.

Je pense que le problème vient dés la génération du schéma

Schéma
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
Faq:
  actAs: 
    Timestampable: ~
    I18n:
      fields: [question,answer]
  columns:
    question:     { type: string(255), notnull: true }
    answer:       { type: string(4000), notnull: true }
    url:          { type: string(255) }
    token:        { type: string(255), notnull: true, unique: true }
    is_public:    { type: boolean, notnull: true, default: 1 }
    is_activated: { type: boolean, notnull: true, default: 0 }
    expires_at:   { type: timestamp, notnull: true }
/lib/model/doctrine/base/BaseFAQ.class.php
Code :
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
abstract class BaseFaq extends sfDoctrineRecord
{
    public function setTableDefinition()
    {
        $this->setTableName('faq');
        $this->hasColumn('question', 'string', 255, array(
             'type' => 'string',
             'notnull' => true,
             'length' => 255,
             ));
        $this->hasColumn('answer', 'string', 4000, array(
             'type' => 'string',
             'notnull' => true,
             'length' => 4000,
             ));
        $this->hasColumn('url', 'string', 255, array(
             'type' => 'string',
             'length' => 255,
             ));
        $this->hasColumn('token', 'string', 255, array(
             'type' => 'string',
             'notnull' => true,
             'unique' => true,
             'length' => 255,
             ));
        $this->hasColumn('is_public', 'boolean', null, array(
             'type' => 'boolean',
             'notnull' => true,
             'default' => 1,
             ));
        $this->hasColumn('is_activated', 'boolean', null, array(
             'type' => 'boolean',
             'notnull' => true,
             'default' => 0,
             ));
        $this->hasColumn('expires_at', 'timestamp', null, array(
             'type' => 'timestamp',
             'notnull' => true,
             ));
    }
 
    public function setUp()
    {
        parent::setUp();
        $timestampable0 = new Doctrine_Template_Timestampable();
        $i18n0 = new Doctrine_Template_I18n(array(
             'fields' => 
             array(
              0 => 'question',
              1 => 'answer',
             ),
             ));
        $sluggable1 = new Doctrine_Template_Sluggable(array(
             'fields' => 
             array(
              0 => 'question',
             ),
             'uniqueBy' => 
             array(
              0 => 'lang',
              1 => 'question',
             ),
             ));
        $i18n0->addChild($sluggable1);
        $this->actAs($timestampable0);
        $this->actAs($i18n0);
    }
}
On commence à voir apparaitre le problème dans le fichier : /lib/form/doctrine/base/baseFAQform.class.php
Code :
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
abstract class BaseFaqForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'           => new sfWidgetFormInputHidden(),
      'question'     => new sfWidgetFormInputText(),
      'answer'       => new sfWidgetFormTextarea(),
      'url'          => new sfWidgetFormInputText(),
      'token'        => new sfWidgetFormInputText(),
      'is_public'    => new sfWidgetFormInputCheckbox(),
      'is_activated' => new sfWidgetFormInputCheckbox(),
      'expires_at'   => new sfWidgetFormDateTime(),
      'created_at'   => new sfWidgetFormDateTime(),
      'updated_at'   => new sfWidgetFormDateTime(),
    ));
 
    $this->setValidators(array(
      'id'           => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'question'     => new sfValidatorString(array('max_length' => 255)),
      'answer'       => new sfValidatorString(array('max_length' => 4000)),
      'url'          => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'token'        => new sfValidatorString(array('max_length' => 255)),
      'is_public'    => new sfValidatorBoolean(array('required' => false)),
      'is_activated' => new sfValidatorBoolean(array('required' => false)),
      'expires_at'   => new sfValidatorDateTime(),
      'created_at'   => new sfValidatorDateTime(),
      'updated_at'   => new sfValidatorDateTime(),
    ));
 
    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'Faq', 'column' => array('token')))
    );
 
    $this->widgetSchema->setNameFormat('faq[%s]');
 
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 
    $this->setupInheritance();
 
    parent::setup();
  }
 
  public function getModelName()
  {
    return 'Faq';
  }
 
}
on voit dans ce fichier que les champs question et answer apparaissent alors qu'il ne devrait pas étant donné qu'ils devaient être transférés dans la table FAQtranslation.

Si on prend le fichier translation:
/lib/form/doctrine/base/baseFAQTranslationform.class.php

Code :
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
abstract class BaseFAQTranslationForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'       => new sfWidgetFormInputHidden(),
      'question' => new sfWidgetFormInputText(),
      'answer'   => new sfWidgetFormTextarea(),
      'lang'     => new sfWidgetFormInputHidden(),
      'slug'     => new sfWidgetFormInputText(),
    ));
 
    $this->setValidators(array(
      'id'       => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'question' => new sfValidatorString(array('max_length' => 255)),
      'answer'   => new sfValidatorString(array('max_length' => 4000)),
      'lang'     => new sfValidatorChoice(array('choices' => array($this->getObject()->get('lang')), 'empty_value' => $this->getObject()->get('lang'), 'required' => false)),
      'slug'     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
    ));
 
    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'FAQTranslation', 'column' => array('slug', 'lang', 'question')))
    );
 
    $this->widgetSchema->setNameFormat('faq_translation[%s]');
 
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 
    $this->setupInheritance();
 
    parent::setup();
  }
 
  public function getModelName()
  {
    return 'FAQTranslation';
  }
 
}
on voit que là aussi les champs question et answer apparaissent ce qui est normal.

Quelqu'un peut il me filer un petit coup de mains?

Volfield
volfield est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/03/2011, 08h32   #2
Modérateur
 
Avatar de Michel Rotta
 
Homme Michel Rotta
Responsable d'exploitation informatique
Inscription : septembre 2005
Messages : 4 913
Détails du profil
Informations personnelles :
Nom : Homme Michel Rotta
Âge : 49
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Responsable d'exploitation informatique
Secteur : Distribution

Informations forums :
Inscription : septembre 2005
Messages : 4 913
Points : 7 505
Points : 7 505
C'est bizarre.

Pourquoi mettre le détail du BaseFAQ.class.php ? Y-as-tu touché ?

Je ne comprend pas non plus la présence d'un champ slug dans baseFAQTranslationform.class.php alors qu'il n'apparait pas dans le shema.yml ?

A mon avis tu as généré avant de mettre en place les form.

Essaie de supprimer dans les dossiers lib/form/doctrine/base et même chose pour model et filter les dossiers base. Attention, il y a un fichier BaseForm.class.php qui ne doit pas être supprimé, il n'est pas auto-régénéré.
__________________
Si tu donnes un poisson à un homme, il mangera un jour. Si tu lui apprends à pêcher, il mangera toujours (Lao Tseu).
  • Pensez à valoriser les réponses pertinantes, cliquez sur le bouton vert +1 pour indiquer votre accord avec la solution proposée.
  • Pensez à utiliser la balise [code] pour afficher du code, elle est cachée sous le bouton [#] dans l'éditeur.
  • Une discussion est terminée ? Alors le bouton est votre ami !
Michel Rotta est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h41.


 
 
 
 
Partenaires

Hébergement Web