Bonjour,

cela fait maintenant plusieurs jours que je cherche mon erreur sur le forum ou sur internet mais je n'arrive toujours pas à trouver

Petite mise en situation:

Version symfony: 1.4.18

Je veux juste que des utilisateurs créer des articles.
Jusque là rien de bien sorcier...

Voici mon schema.yml: (je suis partis de rien, pas d'export de base existante ou autre joyeuseté)

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
User:
  tableName: user
  columns:
    firstname:
      type: string(45)
      notnull: true
    lastname:
      type: string(45)
      notnull: true
    email:
      type: string(100)
      notnull: true
      unique: true
    password:
      type: string(40)
      notnull: true
    salt:
      type: string(40)
      notnull: true
    url:
      type: string(255)
      notnull: true
    state:
      type: integer(1)
      notnull: true
      unsigned: true
      default: 0
 
Article:
  tableName: article
  columns:
    user_id:
      type: integer
      notnull: true
    category:
      type: string(50)
      notnull: true
    title:
      type: string(100)
      notnull: true
    content:
      type: text
      notnull: true
    note:
      type: float(4,2)
      notnull: true
    state:
      type: integer(1)
      notnull: true
      default: 1
  relations:
    User:
      foreignAlias: Articles #lien many to one
j'ai mis en place mon formulaire:

ArticleForm.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
 
<?php
 
/**
 * Article form.
 *
 * @package    plop
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ArticleForm extends BaseArticleForm
{
  public function configure()
  {
    $this->useFields(array('category', 'title', 'content', 'state', 'note', 'user_id'));
 
    $this->setWidgets(array(
        'category'  => new sfWidgetFormInput(),
		'title'		=> new sfWidgetFormInput(),
		'content'	=> new sfWidgetFormTextarea(),
	));
 
	$this->widgetSchema->setLabels(array(
    	'category'		=> 'Votre category: ',
		'title'		=> 'Votre titre: ',
		'content'	=> 'Votre article: ',
	));
 
	$this->widgetSchema->setNameFormat('article[%s]');
 
	$this->setValidators(array(
		'category'	=> new sfValidatorString(
				array('required' => true, 'min_length' => 3, 'max_length' => 100),
				array(
					'min_length' => "Le titre doit contenir minimum 3 caracteres.",
					'max_length' => "Le titre doit contenir maximum 100 caracteres.",
					'required' => "Votre titre est requis.",
					'invalid' => "Le titre ne doit pas contenir de carateres speciaux."
				)),
		'title'	=> new sfValidatorString(
				array('required' => true, 'min_length' => 3, 'max_length' => 100),
				array(
					'min_length' => "Le titre doit contenir minimum 3 caracteres.",
					'max_length' => "Le titre doit contenir maximum 100 caracteres.",
					'required' => "Votre titre est requis.",
					'invalid' => "Le titre ne doit pas contenir de carateres speciaux."
				)),
		'content'	=> new sfValidatorString(
				array('required' => true, 'min_length' => 3, 'max_length' => 2000),
				array(
					'min_length' => "L'article doit contenir minimum 3 caracteres.",
					'max_length' => "L'article doit contenir maximum 2000 caracteres.",
					'required' => "Votre article est requis.",
					'invalid' => "L'article ne doit pas contenir de carateres speciaux."
				)),
	));
  }
}
Enfin j'ai modifié ma vue:

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
 
<article>
	<form action="<?php echo url_for('article/create'); ?>" method="post" id="new-article">
		<fieldset>
			<legend><?php echo "Creer un article"; ?></legend>
			<ul id="article-form">
				<?php foreach ($form as $widget): ?>
					<?php if (!$widget->isHidden()) { ?>
						<li>
							<span>
								<?php echo $widget->renderLabel(); ?>
								<?php echo $widget->renderHelp() ?><br />
							</span>
								<?php echo $widget->render() ?>
						</li>
					<?php } else { ?>
						<li><?php echo $widget->render() ?></li>
					<?php } ?>
				<?php endforeach; ?>
			</ul>
			<p><input type="submit" id="submit" value="<?php echo "Poster votre article"; ?>" /></p>
		</fieldset>
	</form>
</article>
et le controller (fonction processForm):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $article = $form->save();
 
      $article->setUserId(1);
      $article->setNote(10);
      $article->save();
 
      $this->redirect('article/edit?id='.$article->getId());
    }
J'ai suivis les tutos jobeet mais j'ai du rater quelque chose.
Je n'arrive pas à setter l'utilisateur que je veux pour l'article, il me sort une erreur sql:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`plop`.`article`, CONSTRAINT `article_user_id_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))
Merci d'avance pour l'aide que vous pourriez m'apporter, je ne vois plus vraiment ou chercher...

Bonne journée.
Cordialement.