Laravel define default layout from controller in good way

前端 未结 3 1449
予麋鹿
予麋鹿 2021-01-05 15:52

I googled two hours, but not found answer. Maybe you can help.

When I define in MyController:

class MyController extends Base_Cont         


        
3条回答
  •  误落风尘
    2021-01-05 16:34

    To use layouts in controllers, you must specify:

    public $layout = 'layouts.default';
    

    You can also not return in the method as it will override the use of $layout. Instead, to embed your content within the layout you use:

    $this->layout->nest('content', 'entries.index', array('entries' => $entries));
    

    No need to return anything in your method now. This will fix it.


    Edit:

    "Beautiful Ways?"

    $this->layout->nest('content', 'entries.index')->with('entries', $entries);
    
    
    $this->layout->content = View::make('entries.index')->with('entries', $entries);
    
    
    $this->layout->entries = $entries;
    $this->layout->nest('content', 'entries.index');
    

提交回复
热议问题