0

I'm having a strange issue with Yii and a theme. I set it in config/main.php like:

'theme'=>'themeName',

as usual. But when I try to render a view, it is rendered as is, without any layout, as if I called:

$this->renderPartial 

I double check that I don't call for renderPartial, the themes seem to be equal to all the others theme I've done. What can be this issue about?

Thank's for any help, I'm going out of mind on this...

4

1 回答 1

0

这是您应该检查的结构和语法

-yiiroot
-!-!protected
-!-!-!controllers
-!-!-!-!TestController.php 
-!-!themes
-!-!-!themeName (it was the one that you have set on config file)
-!-!-!-!views
-!-!-!-!-!layouts
-!-!-!-!-!-!main.php // It would be default what if public $layout has not been overwriten or the layout file which has been set was not found     
-!-!-!-!-!test
-!-!-!-!-!-!viewName.php 

在控制器上TestController

  • public$layout是默认的 main 或在那里被覆盖

  • actionIndex你设置$this->render('viewName');

如果您renderPartial()直接在控制器中通过方法渲染页面,您肯定不会获得布局模板

render()通常用于渲染与用户在应用程序中看到的“页面”相对应的视图。它首先渲染您指定的视图,然后渲染当前控制器操作的布局(如果适用),将第一次渲染的结果放入布局中。然后它执行输出处理(此时意味着自动插入任何必要的标签并更新动态内容)并最终输出结果。

renderPartial()通常用于渲染页面的“片段”。与 render() 的主要区别在于此方法不会将渲染结果放在布局中。默认情况下,它也不执行输出处理,但您可以使用 $processOutput 参数覆盖此行为。

renderFile()是一个低级方法,它完成繁重的渲染工作:它提取当前范围内的数据变量,然后运行视图代码。其他两种方法在内部调用此方法,但实际上您应该永远不需要自己调用它。如果这样做,请记住您需要传入文件路径(而不是视图路径)。

参考:Yii 渲染函数的区别

于 2013-08-07T14:13:11.173 回答