您的位置:首页 > 其它

在windows上使用symfony创建简易的CMS系统(二)

2013-11-09 10:51 423 查看
http://blog.csdn.net/kunshan_shenbin/article/details/7165013

这次主要讲诉如何完成前台展示页面的开发:

依次运行如下指令:

>symfony generate:module frontend home

>symfony doctrine:generate-module frontend category Category

>symfony doctrine:generate-module frontend content Content

修改首页路由:

打开cms/apps/frontend/config/routing.yml, 找到:

homepage:
url: /
param: { module: default, action: index }

修改为:

homepage:
url: /
param: { module: home, action: index }

保存后,可直接通过输入http://localhost:1300/frontend_dev.php/访问首页

实现首页:

找到cms/apps/frontend/modules/home/actions/actions.class.php,写入代码:

[php] view plaincopy

<?php

/**

* home actions.

*

* @package cms

* @subpackage home

* @author Your name here

* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $

*/

class homeActions extends sfActions

{

/**

* Executes index action

*

* @param sfRequest $request A request object

*/

public function executeIndex(sfWebRequest $request)

{

//$this->forward('default', 'module');

$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,写入代码:

[html] view plaincopy

<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 />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: