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

Yii Framework Tutorial (13) UI component ContentDecorator example

黄舟
Release: 2023-03-05 07:36:01
Original
1080 people have browsed it

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();
Copy after login

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(); ?>
Copy after login

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 (m.sbmmt.com)!


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template