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 : Sélectionner tout - Visualiser dans une fenêtre à part
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 : 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
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 : 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
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 : 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
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