http://blog.csdn.net/kunshan_shenbin/article/details/7165013php
此次主要講訴如何完成前臺展現頁面的開發:html
依次運行以下指令:app
>symfony generate:module frontend homefrontend
>symfony doctrine:generate-module frontend category Categoryoop
>symfony doctrine:generate-module frontend content Contentthis
修改首頁路由:url
打開cms/apps/frontend/config/routing.yml, 找到:spa
homepage:
url: /
param: { module: default, action: index }.net
修改成:symfony
homepage:
url: /
param: { module: home, action: index }
保存後,可直接經過輸入http://localhost:1300/frontend_dev.php/訪問首頁
實現首頁:
找到cms/apps/frontend/modules/home/actions/actions.class.php,寫入代碼:
- <?php
-
-
-
-
-
-
-
-
-
- class homeActions extends sfActions
- {
-
-
-
-
-
- public function executeIndex(sfWebRequest $request)
- {
-
-
- $this->categories = Doctrine::getTable('Category')
- ->findAll();
-
- $this->lastestList = Doctrine::getTable('Content')
- ->createQuery('c')
- ->orderBy('c.created_at desc')
- ->limit(6)
- ->execute();
-
- $this->hotViewedList = Doctrine::getTable('Content')
- ->createQuery('c')
- ->orderBy('c.view_count desc')
- ->limit(6)
- ->execute();
-
- $this->hotCommentedList = Doctrine_Query::create()
- ->from('Content c')
- ->leftJoin('c.Comments m')
- ->select('c.title, COUNT(m.id) mun_comments')
- ->groupBy('c.id')
- ->orderBy('mun_comments desc')
- ->limit(6)
- ->execute();
-
- $this->hotRecommendList = Doctrine::getTable('Content')
- ->createQuery('c')
- ->where('c.recommend_level = 0')
- ->orderBy('c.created_at desc')
- ->limit(6)
- ->execute();
- }
- }
找到cms/apps/frontend/modules/home/actions/indexSuccess.php,寫入代碼:
- <div>
- <a href="<?php echo url_for("@homepage"); ?>">首頁</a>
- <?php foreach ($categories as $category) :?>
- <a href="<?php echo url_for("category/edit?id=".$category->getId()); ?>">
- <?php echo $category->getName(); ?>
- </a>
- <?php endforeach; ?>
- </div>
-
- <div>
- <h3>最近資訊</h3>
- <?php foreach ($lastestList as $topic) :?>
- <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">
- <?php echo $topic->getTitle(); ?></a>
- </li>
- <?php endforeach; ?>
- </div>
- <hr/>
-
- <div>
- <h3>熱點資訊</h3>
- <?php foreach ($hotViewedList as $topic) :?>
- <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">
- <?php echo $topic->getTitle(); ?></a>
- </li>
- <?php endforeach; ?>
- </div>
- <hr />
-
- <div>
- <h3>熱評資訊</h3>
- <?php foreach ($hotCommentedList as $topic) :?>
- <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">
- <?php echo $topic->getTitle(); ?>(<?php echo $topic->mun_comments; ?>)</a>
- </li>
- <?php endforeach; ?>
- </div>
- <hr />
-
- <div>
- <h3>推薦資訊</h3>
- <?php foreach ($hotRecommendList as $topic) :?>
- <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">
- <?php echo $topic->getTitle(); ?></a>
- </li>
- <?php endforeach; ?>
- </div>
- <hr />