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

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

本文主要讲述component的使用。

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

<?php 

class homeComponents extends sfComponent {

	function execute($request) {
		
	}
	
	function executeNavigator($request) {
	
		$this->categories = Doctrine::getTable('Category')
		->findAll();
	}
}

?>

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


在cms/apps/frontend/modules/home/actions/中新建_navigator.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>

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


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

<!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>
  	<?php include_component('home', 'navigator'); ?>
        <?php echo $sf_content ?>
  </body>
</html>

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


你可能感兴趣的:(cms,windows,function,XHTML,include,Doctrine)