YII模板(前台显示)详细分析

1. Yii framwork renderPartial 的用法

<?php echo $this->renderPartial('/default/add_news');?>
<?php echo $this->renderPartial('//public/footer');?>

absolute view within a module: the view name starts with a single slash '/'. 
absolute view within the application: the view name starts with double slashes '//'.

当前module下的view文件使用/
外层views下的view文件用//
2.render是调用layout渲染一个view,并显示出来。renderPrtial直接显示一个view。renderText是显示一个静态的string字符串

第一部分,分析模板中所用到的YII变量及方法总结

模板中用的到变量:
<?php echo Yii::app()->request->baseUrl; ?> URL目录
<?php echo CHtml::encode($this->pageTitle); ?> 网页标题信息

<?php echo CHtml::encode(Yii::app()->name); ?> 网站名称,配置信息中声明
<?php echo Yii::powered(); ?> 版权信息


调用模板片段
<?php $this->widget('zii.widgets.CMenu',array('items'=>array(..))) ?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array( 'links'=>array(..)))?>

输出组件主要内容
<?php echo $content; ?>


第二部分,分析内容输出调用方式
CApplication.run->CWebApplication.processRequest->CWebApplication.runController->$controller.init,$controller.run($actionID)->PostController.actionID(){ .. $this->render()..}
以上是调用经过,处理模板是在 CController.render 方法中,先处理action生成output作为内容,然后再处理layout模板进行输出.

1,用布局作为内容处理过程
  $this->beginContent('/layouts/main');->$this->beginWidget('CContentDecorator',array('view'=>$view, 'data'=>$data));
  ...
  $this->endContent(); ->$this->endWidget('CContentDecorator');


第三部分,beginWidget 和 endWidget 方式加载模板内容
beginWidget-> COutputProcessor.init()
       {
              ob_start();
              ob_implicit_flush(false);
       }
...

endWidget->COutputProcessor.run()
       {
              $output=ob_get_clean();
              $this->processOutput($output);
       }

以上是YII框架处理视图的基本形式,这种方式主要用于在代码中直接传参数,一些开源的CMS中,则是通过后台来自定义参数配置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值