【问题标题】:Cakephp 2.6 Layouts are not loading only view is renderedCakephp 2.6 布局未加载仅呈现视图
【发布时间】:2016-03-17 11:15:53
【问题描述】:

我使用的是 cakephp 2.6 版。我的主要问题是只呈现了一个动作的视图,但没有应用布局。它发生在整体动作上。是否是服务器问题 我在 AppController.php 中应用了默认布局,但仍然无法正常工作

public function beforeFilter() {
       $this->layout = 'default';
}

提前致谢。

【问题讨论】:

  • 首先deafult会自动加载。第二,如果你想这样做,那么要么在AppbeforeRender() 中执行,要么执行特定操作,然后只写$this->layout = 'some other layout';
  • 我在各自的操作中使用了 $this->layout = 'default',但有时它会被应用,而其他时间只呈现视图。查看源代码时只显示视图代码,而不是布局。
  • @AsimKatamale 有没有任何类型的错误,例如数据库未连接等。
  • 没有数据库错误,代码在我的本地服务器上运行良好,但在 LIVE 服务器和 LIVE 服务器 PHP 版本为 5.4 上运行良好
  • 想象一下,如果我们添加了 $this->autoRender = false 或 $this->layout = null,这种类型的视图会显示出来,在某些情况下也会显示,其他时候它可以工作很好

标签: php cakephp


【解决方案1】:

如果您使用 default.ctp 作为默认布局方式,则不要包含以下行。

$this->layout = 'default';

因为 cakephp 默认渲染为“default.ctp”布局。

如果你想要其他布局 "someotherlayout.ctp"

调用方法

$this->layout = 'someotherlayout';

假设,您不需要布局并且需要一些没有布局的主要内容。确保布局文件夹中有“ajax.ctp”。

$this->layout = 'ajax';

假设,你不需要布局,需要一些没有布局的主要数据

$this->autoRender = false;
//provide the data or redirect some other page

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多