下記はcakePHPのbakeで生成されたindex.ctpです。
cakePHPを使いはじめて1週間ぐらいなのであまりわからないのですが、DBからの出力を辿っていくと、
foreach ($posts as $post)
で
$post['Post']['id']のように出力していて
仕組みが知りたくて辿って行ってるのですが
$postsに代入している記述( foreach ($posts as $post)
から前の記述)が見当たりません。
テーブルはpostsとauthorsを作ってbakeしてできたファイルなので何も考えずにテーブル名がそのまま使えるのかと思うのですがどうなんでしょうか。
<div class="posts index"> <h2><?php echo $this->Html->link('物件一覧', array('action' => 'index')); ?></h2> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th><?php echo $this->Paginator->sort('id','ID'); ?></th> <th><?php echo $this->Paginator->sort('title','タイトル'); ?></th> <th><?php echo $this->Paginator->sort('body','本文'); ?></th> <th><?php echo $this->Paginator->sort('author_id','作者'); ?></th> <th><?php echo $this->Paginator->sort('created','作成日'); ?></th> <th><?php echo $this->Paginator->sort('modified','更新日'); ?></th> <th class="actions"><?php echo __('操作'); ?></th> </tr> </thead> <tbody> <?php foreach ($posts as $post): ?> <tr> <td><?php echo h($post['Post']['id']); ?> </td> <td><?php echo h($post['Post']['title']); ?> </td> <td><?php echo h($post['Post']['body']); ?> </td> <td> <?php echo $this->Html->link($post['Author']['name'], array('controller' => 'authors', 'action' => 'view', $post['Author']['id'])); ?> </td> <td><?php echo h($post['Post']['created']); ?> </td> <td><?php echo h($post['Post']['modified']); ?> </td> <td class="actions"> <?php echo $this->Html->link(__('閲覧'), array('action' => 'view', $post['Post']['id'])); ?> <?php echo $this->Html->link(__('編集'), array('action' => 'edit', $post['Post']['id'])); ?> <?php echo $this->Form->postLink(__('削除'), array('action' => 'delete', $post['Post']['id']), array('confirm' => __('Are you sure you want to delete # %s?', $post['Post']['id']))); ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <p> <?php echo $this->Paginator->counter(array( 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') )); ?> </p> <div class="paging"> <?php echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled')); echo $this->Paginator->numbers(array('separator' => '')); echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled')); ?> </div> </div> <div class="actions"> <h3><?php echo __('Actions'); ?></h3> <ul> <li><?php echo $this->Html->link(__('新規投稿'), array('action' => 'add')); ?></li> <li><?php echo $this->Html->link(__('投稿者一覧'), array('controller' => 'authors', 'action' => 'index')); ?> </li> <li><?php echo $this->Html->link(__('投稿者追加'), array('controller' => 'authors', 'action' => 'add')); ?> </li> </ul> 検索 </div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/26 15:59