如何在Laravel控制器中使用$ layout

时间:2013-02-11 15:35:05

标签: php laravel

我尝试在控制器中使用$layout属性,但我总是遇到以下错误:

  

在非对象

上调用成员函数nest()

dd() this->layout的值时,它似乎只是一个字符串。

这是我的代码:

base.php

class Base_Controller extends Controller {
  public $layout = 'layouts.common';
}

admin.php的

class Admin_Controller extends Base_Controller {
  public function action_index() {
    $this->layout->nest('content', 'admin.home');
  }
}

我可能会错过一些东西,但我在文档中找不到它

1 个答案:

答案 0 :(得分:0)

啊,刚刚发现了麻烦。我正在编写__construct来添加过滤器,但没有调用父构造:

class Admin_Controller extends Base_Controller {
  public function __construct() {
    parent::__construct();
    $this->filter('before', 'auth');
  }
  public function action_index() {
    $this->layout->nest('content', 'admin.home');
  }
}