カテゴリ一覧表示を作る5
では親カテゴリ一覧を作ります。
例によって indexアクションに手を入れます。
/var/www/podtv/apps/frontend/modules/category_new/actions/actions.class.php
<?php // auto-generated by sfPropelCrud // date: 2008/05/11 16:44:48 ?> <?php /** * category_new actions. * * @package podtvlabo * @subpackage category_new * @author Your name here * @version SVN: $Id: actions.class.php 3335 2007-01-23 16:19:56Z fabien $ */ class category_newActions extends sfActions { public function executeIndex() { // return $this->forward('category_new', 'list'); // parent_category_idが無ければ、親カテゴリと判断する。 $c = new Criteria(); $c->add( CategoryNewPeer::PARENT_CATEGORY_ID, NULL, Criteria::ISNULL); $this->category_news = CategoryNewPeer::doSelect( $c); return sfView::SUCCESS; }
次に viewは特に変更なし。自動生成された listそのまま。
/var/www/podtv/apps/frontend/modules/category_new/templates /indexSuccess.php
<?php // auto-generated by sfPropelCrud // date: 2008/05/11 16:44:48 ?> <h1>category_new</h1> <table> <thead> <tr> <th>Id</th> <th>Name</th> <th>Parent category</th> <th>Created at</th> <th>Updated at</th> </tr> </thead> <tbody> <?php foreach ($category_news as $category_new): ?> <tr> <td><?php echo link_to($category_new->getId(), 'category_new/show?id='.$category_new-> getId()) ?></td> <td><?php echo $category_new->getName() ?></td> <td><?php echo $category_new->getParentCategoryId() ?></td> <td><?php echo $category_new->getCreatedAt() ?></td> <td><?php echo $category_new->getUpdatedAt() ?></td> </tr> <?php endforeach; ?> </tbody> </table> <?php echo link_to ('create', 'category_new/create') ?>
で、これは順調に出来ました。
http://podtvlabo.com/frontend_dev.php/category_new
さて、次は子カテゴリです。