http://blog.csdn.net/kunshan_shenbin/article/details/7168249javascript
本文主要講述component的使用。php
在cms/apps/frontend/modules/home/actions/中新建components.class.php文件,代碼以下。html
- <?php
-
- class homeComponents extends sfComponent {
-
- function execute($request) {
-
- }
-
- function executeNavigator($request) {
-
- $this->categories = Doctrine::getTable('Category')
- ->findAll();
- }
- }
-
- ?>
修改actions.class.php文件,去掉$this->categories = 。。。這一行。java
在cms/apps/frontend/modules/home/actions/中新建_navigator.php文件(注意文件名是如下劃開頭的)app
代碼以下:frontend
- <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>
打開indexSuccess.php,去掉上述首頁導航條的代碼。oop
修改cms/apps/frontend/templates/layout.php文件,代碼以下:this
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <?php include_http_metas() ?>
- <?php include_metas() ?>
- <?php include_title() ?>
- <link rel="shortcut icon" href="/favicon.ico" />
- <?php include_stylesheets() ?>
- <?php include_javascripts() ?>
- </head>
- <body>
- <strong><?php include_component('home', 'navigator'); ?></strong>
- <?php echo $sf_content ?>
- </body>
- </html>
從新訪問http://localhost:1300/frontend_dev.php/,點擊導航條,能夠發現導航已經能在全部頁面的上方顯示了。url