Bonjour à tous,

Voila je commence à me familiariser avec ce framework qui à franchement l'air bien sympa mais j'ai un soucis sur mon test. C'est une gestion d'article ultra basique pour l'instant que je vais compléter au fur et à mesure de mon apprentissage.

Au lieu de faire une longue explication je vais vous donner mon code et après le résultat que je ne comprends pas.

Mon contrôleur ContenuArticlesController.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
<?php
class ContenuArticlesController extends AppController {
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');
 
    public function index() {
        $this->set('contenuarticles', $this->ContenuArticle->find('all'));
    }
 
    ....
 
    public function edit($id = null) {
	    if (!$id) {
	        throw new NotFoundException(__('Invalid post'));
	    }
 
	    $article = $this->ContenuArticle->findById($id);
	    if (!$article) {
	        throw new NotFoundException(__('Invalid post'));
	    }
 
	    if ($this->request->is('article') || $this->request->is('put')) {
	        $this->ContenuArticle->id = $id;
	        if ($this->ContenuArticle->saveAssociated($this->request->data)) {
	            $this->Session->setFlash(__('Your post has been updated.'));
	            return $this->redirect(array('action' => 'index'));
	        }
	        $this->Session->setFlash(__('Unable to update your post.'));
	    }
 
	    if (!$this->request->data) {
	        $this->request->data = $article;
	    }
	}
 
     ...
}
?>
Mon modèle ContenuArticle.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
<?php
class ContenuArticle extends AppModel {
	public $validate = array(
	    'trad_article_titre' => array(
	        'rule' => 'notEmpty'
	    ),
	    'trad_article_texte' => array(
	        'rule' => 'notEmpty'
	    )
	);
 
	public $hasOne = array(
        'ContenuTradArticle' => array(
            'className' => 'ContenuTradArticle',
            'foreignKey' => 'trad_article_article_id',
            'conditions' => array('trad_article_langue_id' => '1'),
            'dependent' => true
        )
    );
}
?>
la vue qui liste les articles, index.ctp:
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
<!-- File: /app/View/ContenuArticles/index.ctp -->
 
<h1>Articles</h1>
<?php echo $this->Html->link(
    'Ajouter un Article',
    array('controller' => 'contenuarticles', 'action' => 'add')
); ?>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Action</th>
        <th>Created</th>
    </tr>
 
    <!-- Here is where we loop through our $posts array, printing out post info -->
 
    <?php foreach ($contenuarticles as $contenuarticle): ?>
    <tr>
        <td><?php echo $contenuarticle['ContenuArticle']['id']; ?></td>
        <td>
            <?php echo $this->Html->link($contenuarticle['ContenuTradArticle']['trad_article_titre'], array('action' => 'view', $contenuarticle['ContenuArticle']['id'])); ?>
        </td>
        <td>
        	<?php echo $this->Form->postLink(
                'Delete',
                array('action' => 'delete', $contenuarticle['ContenuArticle']['id']),
                array('confirm' => 'Etes-vous sûr ?'));
            ?>
            <?php echo $this->Html->link('Edit', array('action' => 'edit', $contenuarticle['ContenuArticle']['id'])); ?>
        </td>
        <td>
            <?php echo $contenuarticle['ContenuArticle']['created']; ?>
        </td>
    </tr>
	<?php endforeach; ?>
 
    <?php unset($contenuarticle); ?>
</table>
La vue qui sert à éditer un article, edit.ctp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Fichier: /app/View/ContenuArticles/edit.ctp -->
 
<h1>Editer le post</h1>
<?php
    echo $this->Form->create('ContenuArticle', array('action' => 'edit'));
    echo $this->Form->input('ContenuTradArticle.trad_article_titre', array('label' => 'Titre'));
    echo $this->Form->input('ContenuTradArticle.trad_article_texte', array('label' => 'Texte','type' => 'textarea','rows' => '3'));
    echo $this->Form->input('ContenuArticle.id', array('type' => 'hidden'));
     echo $this->Form->input('ContenuTradArticle.id', array('type' => 'hidden'));
   echo $this->Form->input('ContenuTradArticle.trad_article_langue_id', array('type' => 'hidden','value' => 1));
    echo $this->Form->end('Sauvegarder le post');
?>
J'ai donc deux tables, contenu_articles et contenu_trad_articles:
contenu_articles
id
article_publie
created
modified

contenu_trad_articles
id
trad_article_titre
trad_article_texte
trad_article_article_id (liaison avec la table contenu_articles)
trad_article_langue_id
created
modified

L'affichage de la liste ce passe bien mais quand j'édite un article et que je valide le formulaire ça me redirige sur "/contenu_articles/edit/1" au lieu de "/contenuarticles/edit/1" (et ça n'enregistre pas les modifs non plus) et c'est là où je vois pas ce que je fais de mal pour avoir ce résultat.
J'espère avoir donné assez de détails pour que vous puissiez m'éclairer.

D'avance Merci.