zoukankan      html  css  js  c++  java
  • 在windows上使用symfony创建简易的CMS系统(二)

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

    1. <?php  
    2.   
    3. /** 
    4.  * home actions. 
    5.  * 
    6.  * @package    cms 
    7.  * @subpackage home 
    8.  * @author     Your name here 
    9.  * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ 
    10.  */  
    11. class homeActions extends sfActions  
    12. {  
    13.  /** 
    14.   * Executes index action 
    15.   * 
    16.   * @param sfRequest $request A request object 
    17.   */  
    18.   public function executeIndex(sfWebRequest $request)  
    19.   {  
    20.     //$this->forward('default', 'module');  
    21.       
    22.     $this->categories = Doctrine::getTable('Category')  
    23.                         ->findAll();  
    24.       
    25.     $this->lastestList = Doctrine::getTable('Content')  
    26.                         ->createQuery('c')  
    27.                         ->orderBy('c.created_at desc')  
    28.                         ->limit(6)  
    29.                         ->execute();  
    30.       
    31.     $this->hotViewedList = Doctrine::getTable('Content')  
    32.                         ->createQuery('c')  
    33.                         ->orderBy('c.view_count desc')  
    34.                         ->limit(6)  
    35.                         ->execute();  
    36.                           
    37.     $this->hotCommentedList = Doctrine_Query::create()  
    38.                         ->from('Content c')  
    39.                         ->leftJoin('c.Comments m')  
    40.                         ->select('c.title, COUNT(m.id) mun_comments')  
    41.                         ->groupBy('c.id')  
    42.                         ->orderBy('mun_comments desc')  
    43.                         ->limit(6)  
    44.                         ->execute();  
    45.       
    46.     $this->hotRecommendList = Doctrine::getTable('Content')  
    47.                         ->createQuery('c')  
    48.                         ->where('c.recommend_level = 0')  
    49.                         ->orderBy('c.created_at desc')  
    50.                         ->limit(6)  
    51.                         ->execute();  
    52.   }  
    53. }  


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

      1. <div>  
      2.     <a href="<?php echo url_for("@homepage"); ?>">首页</a>  
      3.     <?php foreach ($categories as $category) :?>  
      4.         <a href="<?php echo url_for("category/edit?id=".$category->getId()); ?>">  
      5.             <?php echo $category->getName(); ?>  
      6.         </a>  
      7.     <?php endforeach; ?>  
      8. </div>  
      9.   
      10. <div>  
      11.     <h3>最近资讯</h3>  
      12.     <?php foreach ($lastestList as $topic) :?>  
      13.         <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">  
      14.             <?php echo $topic->getTitle(); ?></a>  
      15.         </li>  
      16.     <?php endforeach; ?>  
      17. </div>  
      18. <hr/>  
      19.   
      20. <div>  
      21.     <h3>热点资讯</h3>  
      22.     <?php foreach ($hotViewedList as $topic) :?>  
      23.         <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">  
      24.             <?php echo $topic->getTitle(); ?></a>  
      25.         </li>  
      26.     <?php endforeach; ?>  
      27. </div>  
      28. <hr />  
      29.   
      30. <div>  
      31.     <h3>热评资讯</h3>  
      32.     <?php foreach ($hotCommentedList as $topic) :?>  
      33.         <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">  
      34.             <?php echo $topic->getTitle(); ?>(<?php echo $topic->mun_comments; ?>)</a>  
      35.         </li>  
      36.     <?php endforeach; ?>  
      37. </div>  
      38. <hr />  
      39.   
      40. <div>  
      41.     <h3>推荐资讯</h3>  
      42.     <?php foreach ($hotRecommendList as $topic) :?>  
      43.         <li><a href="<?php echo url_for("content/edit?id=".$topic->getId()); ?>">  
      44.             <?php echo $topic->getTitle(); ?></a>  
      45.         </li>  
      46.     <?php endforeach; ?>  
      47. </div>  
      48. <hr />  
  • 相关阅读:
    基于Servlet+JSP+JavaBean开发
    jsp&servlet报红线javax.servlet.jsp.XXXX cannot be resolved to a type类似错误解决办法
    java为什么要定义接口等相关解释
    SpringMVC的注解方式
    MyBatis映射
    hibernate、JDBC 实现 oracle ID 的自动增加 功能
    SSH框架的JSP网站添加数据为什么没反应
    又考完一科 又过完一年
    一个招标书文件的需求分析
    《需求分析》读后感之二
  • 原文地址:https://www.cnblogs.com/kaeloy/p/3415391.html
Copyright © 2011-2022 走看看