Bonjour,

Je rencontre actuellement un problème pour faire une pagination et un tri via l'option Paginator->sort...

Voici mon code :

Controller films_controller.php

var $paginate = array(
            'limit' => 10,
            'order' => array(
                'Film.name' => 'ASC'
            ),
        );
function catfilm($id = null) {
        $this->set('films', $this->paginate());
        if (!$id) {
            $this->Session->setFlash(__('Catégorie non valide', true));
            $this->redirect(array('action' => 'index'));
        }

                $this->Film->id = $id;
                $cat = $this->Film->find('all', array(
                    'order' => 'Film.name ASC',
                    'conditions' => array(
                        'Film.category_id' => $id
                    )
                ));
                $this->set(compact('cat','films'));
    }

Ma vue catfilm.ctp

<?php
$for = $this->requestAction(array(
    "controller"=>"formats",
    "action"=>"getFor"
));
$cate = $this->requestAction(array(
    "controller"=>"categories",
    "action"=>"getCat"
));
?>
<table width="100%">
    <thead>
        <tr>
            <th><?php echo $this->Paginator->sort('Nom','name');?></th>
            <th><?php echo $this->Paginator->sort('Durée','duration');?></th>
            <th><?php echo 'Format';?></th>
            <th><?php echo 'Catégorie';?></th>
            <th><?php echo $this->Paginator->sort('Ajouté le','created');?></th>
        </tr>
    </thead>
    <?php foreach ($cat as $film):?>
    <tr>
        <td><?php echo $film'Film']'name'];?></td>
        <td><?php echo $film'Film']'duration'];?></td>
        <?php foreach ($for as $f):?>
            <?php if($f'Format']'id'] == $film'Film']'format_id']): ?>
                <td><?php echo $f'Format']'name'];?></td>
            <?php endif;?>
        <?php endforeach;?>
        <?php foreach ($cate as $c):?>
            <?php if($c'Category']'id'] == $film'Film']'category_id']): ?>
                <td><?php echo $c'Category']'name'];?></td>
            <?php endif;?>
        <?php endforeach;?>
        <td><?php echo $date->show($film'Film']'created']);?></td>
    </tr>
    <?php endforeach;?>
</table>

Voilà, à l'affichage tout est ok, sauf que je n'ai pas que 10 articles listés, mais la totalité... Mes liens sont présents pour les Paginator->sort mais lorsque je clique dessus, rien ne se passe... Pourtant je vois bien mes requêtes changer dans le debug et mon url aussi...

Mes autres function dans ce controller fonctionnent super bien... C'est à n'y rien comprendre... La pagination n'est tout simplement pas prise en compte...

Merci d'avance pour votre aide

1 réponse


Innah
Auteur
Réponse acceptée

Problème résolu, je poste la solution, au cas où cela intéresse quelqu'un :)

Dans l'envoie de la pagination, il faut préciser les critères sur lequel elle doit se baser :
$this->set('cat', $this->paginate( array('Film.category_id' => $this->Film->id) ));