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

http://blog.csdn.net/kunshan_shenbin/article/details/7168249

本文主要讲述component的使用。

在cms/apps/frontend/modules/home/actions/中新建components.class.php文件,代码如下。

 

[php]  view plain copy
  1. <?php   
  2.   
  3. class homeComponents extends sfComponent {  
  4.   
  5.     function execute($request) {  
  6.           
  7.     }  
  8.       
  9.     function executeNavigator($request) {  
  10.       
  11.         $this->categories = Doctrine::getTable('Category')  
  12.         ->findAll();  
  13.     }  
  14. }  
  15.   
  16. ?>  


修改actions.class.php文件,去掉$this->categories = 。。。这一行。

 

 

在cms/apps/frontend/modules/home/actions/中新建_navigator.php文件(注意文件名是以下划开头的)

代码如下:

 

[html]  view plain copy
  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>  


打开indexSuccess.php,去掉上述首页导航条的代码。

 

 

修改cms/apps/frontend/templates/layout.php文件,代码如下:

 

[html]  view plain copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  3.   <head>  
  4.     <?php include_http_metas() ?>  
  5.     <?php include_metas() ?>  
  6.     <?php include_title() ?>  
  7.     <link rel="shortcut icon" href="/favicon.ico" />  
  8.     <?php include_stylesheets() ?>  
  9.     <?php include_javascripts() ?>  
  10.   </head>  
  11.   <body>  
  12.     <strong><?php include_component('home', 'navigator'); ?></strong>  
  13.         <?php echo $sf_content ?>  
  14.   </body>  
  15. </html>  

 

 

重新访问http://localhost:1300/frontend_dev.php/,点击导航条,可以发现导航已经能在所有页面的上方显示了。

转载于:https://www.cnblogs.com/kaeloy/p/3415397.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值