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

接上文:http://blog.csdn.net/kunshan_shenbin/article/details/7164675

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

依次运行如下指令:

>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

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

<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 />



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值