カテゴリ一覧表示を作る6

それでは、子カテゴリ一覧を作ります。showアクションに手を入れます。

/var/www/podtv/apps/frontend/modules/category_new/actions/actions.class.php

  public function executeShow()
  {
    $this->category_new = CategoryNewPeer::retrieveByPk($this->getRequestParameter('id'));
    // parent_category_idが同じものの一覧を表示。つまりそれが子になる。
    $c = new Criteria();
    $c->add( CategoryNewPeer::PARENT_CATEGORY_ID, $this->getRequestParameter('id'), Criteria::EQUAL);
    $this->child_categorys = CategoryNewPeer::doSelect( $c);
    // ついでにそれが何個あるかも表示させる。
    $this->child_categorys_count = CategoryNewPeer::doCount( $c);
    $this->forward404Unless($this->category_new);
  }

で、viewはこんな感じ。
/var/www/podtv/apps/frontend/modules/category_new/templates/showSuccess.php

<?php
// auto-generated by sfPropelCrud
// date: 2008/05/11 16:44:48
?>
<table>
<tbody>
<tr>
<th>Id: </th>
<td><?php echo $category_new->getId() ?></td>
</tr>
<tr>
<th>Name: </th>
<td><?php echo $category_new->getName() ?></td>
</tr>
<tr>
<th>Parent category: </th>
<td><?php echo $category_new->getParentCategoryId() ?></td>
</tr>
<tr>
<th>Created at: </th>
<td><?php echo $category_new->getCreatedAt() ?></td>
</tr>
<tr>
<th>Updated at: </th>
<td><?php echo $category_new->getUpdatedAt() ?></td>
</tr>
</tbody>
</table>
<br />
<br />
<?php echo '子カテゴリは' .$child_categorys_count .'個あります'?><br />
<?php foreach ($child_categorys as $child_category): ?>

<?php echo link_to( $child_category->getName(), 'category_new/show?id='.$child_category->getId()); ?><br />
<?php endforeach; ?>

<hr />
<?php echo link_to('edit', 'category_new/edit?id='.$category_new->getId()) ?>
&nbsp;<?php echo link_to('list', 'category_new/list') ?>

無事できました。
http://podtvlabo.com/frontend_dev.php/category_new/show/id/7

野球をクリックすると、子カテゴリの詳細が表示されます。
http://podtvlabo.com/frontend_dev.php/category_new/show/id/13

おー、我ながら順調。