当前位置:Gxlcms > PHP教程 > YiiFramework教程(13)UI组件ContentDecorator示例

YiiFramework教程(13)UI组件ContentDecorator示例

时间:2021-07-01 10:21:17 帮助过:15人阅读

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

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

其中view 为另外一个布局。

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

578.png

  1. ///main.php
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title><?php echo Yii::app()->name; ?></title>
  8. </head>
  9. <body>
  10. <h1>Widget Demo</h1>
  11. <?php echo $content; ?>
  12. </body>
  13. </html>
  14. ///row1.php
  15. <?php $this->beginContent('/layouts/row2'); ?>
  16. <center>
  17. <?php echo $content; ?>
  18. </center>
  19. <p />
  20. <center>
  21. <?php echo 'row1 part'; ?>
  22. </center>
  23. <?php $this->endContent(); ?>
  24. //row2.php
  25. <?php $this->beginContent('/layouts/row3'); ?>
  26. <center>
  27. <?php echo $content; ?>
  28. </center>
  29. <p />
  30. <center>
  31. <?php echo 'row2 part'; ?>
  32. </center>
  33. <?php $this->endContent(); ?>
  34. ///row3.php
  35. <?php $this->beginContent('/layouts/main'); ?>
  36. <center>
  37. <?php echo $content; ?>
  38. </center>
  39. <p />
  40. <center>
  41. <?php echo 'row3 part'; ?>
  42. </center>
  43. <?php $this->endContent(); ?>

显示结果如下:

579.png

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

人气教程排行