和java swing中类似yii framework 中的layout 也允许嵌套,这是通过ccontentdecorator来实现的,不过代码中并不需要 直接使用ccontentdecorator ,而是在定义layout使用
$this->beginContent('path/to/view');
// ... content to be decorated
$this->endContent();其中view 为另外一个布局。
本例定义四个Layout,一个嵌套一个:

///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('/layouts/row2'); ?>
<center>
<?php echo $content; ?>
</center>
<p />
<center>
<?php echo 'row1 part'; ?>
</center>
<?php $this->endContent(); ?>
//row2.php
<?php $this->beginContent('/layouts/row3'); ?>
<center>
<?php echo $content; ?>
</center>
<p />
<center>
<?php echo 'row2 part'; ?>
</center>
<?php $this->endContent(); ?>
///row3.php
<?php $this->beginContent('/layouts/main'); ?>
<center>
<?php echo $content; ?>
</center>
<p />
<center>
<?php echo 'row3 part'; ?>
</center>
<?php $this->endContent(); ?>显示结果如下:

以上就是Yii Framework教程(13) UI 组件 ContentDecorator示例的内容,更多相关内容请关注PHP中文网(www.php.cn)!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号