Yii: 利用Clip片断构建复杂界面
Yii: 利用Clip片段构建复杂界面
layout:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Clip</title> </head> <body> <div id="header"> this is header and main menu here </div> <div id="main"> <div id="left"> <?php echo $content ?> </div> <div id="right"> <div class="block"> <?php echo $this->clips['submenu'] ?> </div> <div class="block"> <?php echo $this->clips['desc'] ?> </div> </div> </div> <div id="footer"> footer section </div> </body> </html>
view的实现:
hello, this is the view 1 <?php $this->beginClip('submenu') ?> here is the sub menu for view 1 <?php $this->endClip() ?> <?php $this->beginClip('desc') ?> here is the description for view 1 <?php $this->endClip() ?>
hi, view 2 is here <?php $this->beginClip('submenu') ?> here is the sub menu for view 2 <?php $this->endClip() ?> <?php $this->beginClip('desc') ?> here is the description for view 2 <?php $this->endClip() ?>
注意:
当然clip也不是非常完美, 和django中的block相比,我们不能为每个clip都设定一个初始值,这样我们要在每个view中都给clip赋值,这有点小麻烦