Home  >  Article  >  Backend Development  >  Yii Framework Tutorial (13) UI component ContentDecorator example

Yii Framework Tutorial (13) UI component ContentDecorator example

黄舟
黄舟Original
2017-01-21 10:12:301056browse

Similar to Java Swing, Layout in Yii Framework also allows nesting, which is achieved through CContentDecorator. However, you do not need to use CContentDecorator directly in the code, but use

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

when defining the layout. view is another layout.

This example defines four Layouts, one nested one:

Yii Framework Tutorial (13) UI component ContentDecorator example

///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(); ?>

The displayed results are as follows:

Yii Framework Tutorial (13) UI component ContentDecorator example

The above is the content of the Yii Framework tutorial (13) UI component ContentDecorator example. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn