laravel 4 - How to load different layout for a particular method?

laravel, laravel-4, php

Solution

You can set the layout to be another view per method:

class AController extends BaseController
{
    protected $layout = "templates.layouts.master";
    protected $data = "something";

    public function alt()
    {
        $this->layout = View::make('templates.layouts.alt');
        $this->layout->content = View::make("content", $this->data);
    }
}

If you check out the `BaseController`, you'll see that all it does is call View::make() to set the layout view. You can do the same to over-ride its default.

Problem

I have something like this : ``` class AController extends BaseController { protected $layout = "templates.layouts.master"; protected $data = "something"; public function alt() { // this is wrong // i want to override "templates.layouts.master" // missing something obviously here $this->layout = ??? what should do? $this->layout->content = View::make("content", $this->data); } } ``` In method alt, I wish to use different layout than the default "templates.layouts.master". I have very limited laravel 4 knowledge. This maybe something easy to achieve, but is beyond my knowledge. Possible solutions that I forsee: - define a construct method, and detect what is the current method, and set a different value for $layout (However, I not sure how to get the current method name). - do an assignment like what I put in above. Which is the correct way?

Original source