如何Laravel控制器使用$布局

问题描述:

我尝试使用$layout财产在我的控制器,但我总是得到以下错误:

Call to a member function nest() on a non-object

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'); 
    } 
} 

我可能会错过一些东西,但我不能找到它docs

啊,只是发现了麻烦。我在修改__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'); 
    } 
}