plusieurs 'posts' a modifier en un seul form

Par duffJohn, il y a 13 ans


Bonjour,
voila dans mon back office, je souhaite permettre a l'utilisateur de modifier plusieurs choses dans la page HOME.
Une citation et un auteur.
Ces deux informations sont toutes les deux issues de la table 'posts' de la base de donnée (id/name/slug/content/type/created/online/category_id).

Dans mon PagesController.php

function admin_homepage($id = null){
                //le cas ou l'on envoi le formulaire
        if($this->request->is('put') || $this->request->is('post')){
            if($this->Post->saveAll($this->request->data)){
                $this->Session->setFlash("Le contenu a bien été modifié","notif");
                $this->redirect(array('action'=>"home"));
            }
        }
                //le cas ou l'on consulte la BDD
        else{
            $page=$this->Post->find('first',array(
                'conditions'=> array('Post.name'=>'Home','type'=>'page')
            ));
            $d'page']= current($page);
            $author=$this->Post->find('first',array(
                'conditions'=> array('Post.name'=>'author','type'=>'author')
            ));
            $d'author']= current($author);
            $this->set($d);
            $this->Post->id = $d'page']'id'];
            $this->request->data = $this->Post->read();
        }
    }

Ma vue admin_homepage.ctp (le tableau)

<?php debug($page); debug($author); ?>
<div class="page-header">
        Modifications de la page <?php echo strtoupper($page'name']); ?>
</div>
<?php echo $this->Form->create('Post', array('class' => 'form-horizontal')); ?>
    <?php echo $this->Form->input('name',array('label'=>'Titre','type'=>'hidden')); ?>
    <?php echo $this->Form->input('slug',array('label'=>'URL','type'=>'hidden')); ?>
    <?php echo $this->Form->input('id'); ?>
    <?php echo $this->Form->input('type',array('value'=>'page','type'=>'hidden')); ?>
    <?php echo $this->Form->input('content',array('label'=>'')); ?>
    <?php echo $this->Form->input('online',array('label'=>'En ligne ?','type'=>'checkbox','type'=>'hidden')); ?>
    <?php echo $this->Form->input('author',array('label'=>'auteur','default'=>$author'content'])); ?>
    <?php echo $this->Form->submit('Enregistrer', array('class' => 'btn btn-inverse')); ?>
<?php echo $this->Form->end(); ?>

Les élément envoyé sont donc un seul tableau de type 'posts' avec un champ supplémentaire 'author'

Comment le dissocier afin d'envoyer par la suite grace a son $id (qui sera fixe '40') les infos du content?

Merci par avance

2 réponses

dadam, il y a 13 ans

Tout est dit :)
(sur irc)

duffJohn, il y a 13 ans

Oui merci dadam et je valide ta réponse ;)