altere5's blog

I thought what I'd do was, I'd pretend I was one of those deaf-mutes. ( or shou'd i ? )

CakePHPのお勉強 10回目 お問い合わせ一覧のページ処理(2)

前回に引き続きページ処理(Pagination)関連のお勉強。

なお、だんだん同時に表示する必要のないものもあるが、お勉強なのでそこはスルーで。

(4) 次へ、前への表示

次のページや前のページのリンクを表示。

<table>
    <tr>
        <th>お名前</th>
        <th>メールアドレス</th>
        <th>お問い合わせ日時</th>
    </tr>

    <?php foreach ($contacts as $contact): ?>
    <tr>
        <td><a href="/contacts/detail/?id=<?php echo $contact['Contact']['id']; ?>"><?php echo $contact['Contact']['username']; ?></a></td>
        <td><?php echo $contact['Contact']['email']; ?></td>
        <td><?php echo $contact['Contact']['created']; ?></td>
    </tr>
    <?php endforeach; ?>

</table>

<?php echo $this->Paginator->first($first = '最初', $options = array()); ?>

<?php echo $this->Paginator->prev('前へ', array(), null, array('class' => 'prev disabled')); ?>

<?php echo $this->Paginator->numbers(); ?>

<?php echo $this->Paginator->next('次へ', array(), null, array('class' => 'next disabled')); ?>

<?php echo $this->Paginator->last($last = '最後', $options = array()); ?>
 

20行目で前のページへのリンクの表示設定と出力を実施。
22行目で次のページへのリンクの表示設定と出力を実施。

実際の動作。

f:id:altere5:20131128010449p:plain

ちゃんと動作。

(5) データの件数や表示中のページ番号等の情報を表示

実際に表示対象となっているデータの件数や現在表示しているページ番号等の情報を表示。 これも簡単。

<table>
    <tr>
        <th>お名前</th>
        <th>メールアドレス</th>
        <th>お問い合わせ日時</th>
    </tr>

    <?php foreach ($contacts as $contact): ?>
    <tr>
        <td><a href="/contacts/detail/?id=<?php echo $contact['Contact']['id']; ?>"><?php echo $contact['Contact']['username']; ?></a></td>
        <td><?php echo $contact['Contact']['email']; ?></td>
        <td><?php echo $contact['Contact']['created']; ?></td>
    </tr>
    <?php endforeach; ?>

</table>

<?php echo $this->Paginator->first($first = '最初', $options = array()); ?>

<?php echo $this->Paginator->prev('前へ', array(), null, array('class' => 'prev disabled')); ?>

<?php echo $this->Paginator->numbers(); ?>

<?php echo $this->Paginator->next('次へ', array(), null, array('class' => 'next disabled')); ?>

<?php echo $this->Paginator->last($last = '最後', $options = array()); ?>

<br/><br/>

<?php echo $this->Paginator->counter('ページ:{:page} / {:pages} - 全{:count}件 - 現在{:start}件目から{:end}件目({:current}件)を表示'); ?>
 

30行目で各種情報を出力。

実際の動作。

f:id:altere5:20131128011306p:plain

ちゃんと情報が表示された。それっぽい。

もう少し勉強できる部分もあるが今回はここまで。
必要となった場合に都度補足でお勉強する予定。