在windows上使用symfony建立簡易的CMS系統(三)

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

本文主要講述component的使用。php

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

 

[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 = 。。。這一行。java

 

 

在cms/apps/frontend/modules/home/actions/中新建_navigator.php文件(注意文件名是如下劃開頭的)app

代碼以下:frontend

 

[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,去掉上述首頁導航條的代碼。oop

 

 

修改cms/apps/frontend/templates/layout.php文件,代碼以下:this

 

[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/,點擊導航條,能夠發現導航已經能在全部頁面的上方顯示了。url

相關文章
相關標籤/搜索