首页  >  文章  >  后端开发  >  Yii Framework教程(13) UI 组件 ContentDecorator示例

Yii Framework教程(13) UI 组件 ContentDecorator示例

黄舟
黄舟原创
2017-01-21 10:12:301017浏览

和Java Swing中类似Yii Framework 中的Layout 也允许嵌套,这是通过CContentDecorator来实现的,不过代码中并不需要 直接使用CContentDecorator ,而是在定义layout使用

$this->beginContent('path/to/view');
// ... content to be decorated
$this->endContent();

其中view 为另外一个布局。

本例定义四个Layout,一个嵌套一个:

578.png

///main.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">    
<head>    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
<title><?php echo  Yii::app()->name;    ?></title>    
</head>    

<body>    
<h1>Widget Demo</h1>    

<?php echo $content; ?>    
        
</body>    
</html>    

///row1.php    
<?php $this->beginContent(&#39;/layouts/row2&#39;); ?>    
<center>    
        <?php echo $content; ?>    
</center>    
<p />    
<center>    
        <?php echo &#39;row1 part&#39;; ?>    
</center>    
<?php $this->endContent(); ?>    
        
//row2.php    
<?php $this->beginContent(&#39;/layouts/row3&#39;); ?>    
<center>    
        <?php echo $content; ?>    
</center>    
<p />    
<center>    
        <?php echo &#39;row2 part&#39;; ?>    
</center>    
<?php $this->endContent(); ?>    
        
///row3.php    
<?php $this->beginContent(&#39;/layouts/main&#39;); ?>    
<center>    
        <?php echo $content; ?>    
</center>    
<p />    
<center>    
        <?php echo &#39;row3 part&#39;; ?>    
</center>    
<?php $this->endContent(); ?>

显示结果如下:

579.png

以上就是Yii Framework教程(13) UI 组件 ContentDecorator示例的内容,更多相关内容请关注PHP中文网(www.php.cn)!


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn