How to load a view into a layout?

Asked

Viewed 809 times

6

I’m trying to carry a view within a layout, follows my controller down below:

class IndexController extends BaseController {
    protected $layout = 'admin.layouts.default';

    public function index()
    {
        $this->layout->$this->layoutcontent =  View::make('admin.index');
    }
}

But it is returning the following error:

Attempt to assign Property of non-object

2 answers

4

The Error is in this passage:

$this->layout->$this->layoutcontent =  View::make('admin.index');

The property is content but you have $this->layoutcontent, you should change to :

$this->layout->content = View::make('admin.index');

See also documentation on: Laravel - Controller Layouts (English)

1


To include sub-views within the layout, it can be this way:

@include('view.name')

Passing values:

@include('view.name', array('some'=>'data'))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.