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文件用//
第一部分,分析模板中所用到的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,用布局作为内容处理过程
第三部分,beginWidget 和 endWidget 方式加载模板内容
beginWidget-> COutputProcessor.init()
...
endWidget->COutputProcessor.run()
以上是YII框架处理视图的基本形式,这种方式主要用于在代码中直接传参数,一些开源的CMS中,则是通过后台来自定义参数配置