Php 如何更改控制器中的布局';s法(拉维法)

Php 如何更改控制器中的布局';s法(拉维法),php,laravel,laravel-4,Php,Laravel,Laravel 4,我在Laravel中使用了多个布局,使用的代码如下,它可以工作 class UsersController extends BaseController { public $layout = 'layouts.default'; ... } 但是现在我想更改方法中的布局(在UsersController中) 我该怎么办?因为当我使用$this->layout='layouts.default2' 它总是返回meErrorException:尝试分配非对象的属性您可以在控制器

我在Laravel中使用了多个布局,使用的代码如下,它可以工作

class UsersController extends BaseController {

    public $layout = 'layouts.default';

    ...
}
但是现在我想更改方法中的布局(在UsersController中)

我该怎么办?因为当我使用
$this->layout='layouts.default2'


它总是返回me
ErrorException:尝试分配非对象的属性

您可以在控制器方法中使用:

public function myFunc(){
    $this->layout = View::make('layouts.default2');
    $this->layout->content = View::make('user.myfunc');
}

您可以在控制器方法中使用此选项:

public function myFunc(){
    $this->layout = View::make('layouts.default2');
    $this->layout->content = View::make('user.myfunc');
}