douyue2313
2017-02-19 12:57
浏览 81
已采纳

Laravel在单个函数中加载多个视图

i just know how to call multiple views in a single controller function.

i am trying this:

return  View::make('header');
return  View::make('main');
return  View::make('footer');

Any suggestion.How can i call them?? thanks in advance..

图片转代码服务由CSDN问答提供 功能建议

我只知道如何在单个控制器函数中调用多个视图。

我正在尝试这个:

 返回View :: make('header'); 
return View :: make('main'); 
return View :: make(  'footer'); 
   
 
 

任何建议。如何打电话给他们? 提前知道..

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doublestar2014 2017-02-19 12:58
    已采纳

    You should create a view with sections for ease of re-use. It then allows you to compose the various sections.

    layout.blade.php

    @yield('header')
    @yield('body')
    @yield('footer')
    

    combined.blade.php

    @extends('layouts.layout')
    
    @section('header')
        @include('header')
    @stop
    
    @section('body')
        @include('body')
    @stop
    
    @section('footer')
        @include('footer')
    @stop
    

    Controller

    <?php
    
    function index()
    {
        return view('combined');
    }
    

    Directory structure

    /resources
      /views
        /combined.blade.php
        /layouts
          /layout.blade.php
    
    点赞 打赏 评论
  • doufangzhang4454 2017-02-19 12:58

    return keyword stops execution of your method/function so it'll just ignore the rest of lines.

    You can try concatenate that make calls if it's what you need.

    return  View::make('header') . View::make('main') . View::make('footer');
    

    But maybe it's not what you want to do? Why not using templating systems and include this files in it?

    点赞 打赏 评论

相关推荐 更多相似问题