Laravel产量不起作用

时间:2017-07-30 17:37:56

标签: php laravel routes sections

这是我的路线

Route::get('/', 'SpielplanController@getSpielplan');

这是我的应用布局页面

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Dateneingabe</title>

    <link rel="stylesheet" href="/css/app.css">
    <script src="{{asset('/js/jquery-3.2.1.min.js')}}"></script>

</head>
<body>
    @yield('contentSpiel')
    @yield('A')
</body>
</html>

现在这是我的@yield('contentSpiel')

@extends('app')

@section('contentSpiel')

            <div class="form-group">
                <label for="">Spiele</label>
                <select class="form-control input-sm" name="spiele" id="spiele">

                @foreach($alleSpiele as $alleSpieleOutput)
    
                    <option value="{!! $alleSpieleOutput->heimmannschaft !!}">{{$alleSpieleOutput->heimmannschaft}}</option>
    
                @endforeach
                </select>
            </div>

<script>
    $('#spiele').on('change', function(e){
        console.log(e);

        var spielID = e.target.value;

        //ajax
        $.get('/spieler-table?spielID=' + spielID, function(data){

            //success data
            console.log(data);
        });
    });
</script>

@endsection

这是我的A节

@extends('app')

@section('A')

<h2>asd</h2>

@endsection

我无法理解为什么我在浏览器中只返回@yield('contentSpiel')部分。我需要改变的是@yields都在我的浏览器中吗?

3 个答案:

答案 0 :(得分:0)

您只能从控制器加载一个视图。现在如果你有一个视图,但你想要产生它的多个部分,那么你可以试试这个例子:

 @extends('layouts.app')


    @section('contentSpiel')
    <div class="form-group">
    <label for="">Spiele</label>
<select class="form-control input-sm" name="spiele" id="spiele">
 @foreach($alleSpiele as $alleSpieleOutput) <option value="{!! $alleSpieleOutput->heimmannschaft !!}">$alleSpieleOutput->heimmannschaft}}</option>         
    @endforeach
</select>
    </div>

    <script>
    $('#spiele').on('change', function(e){
    console.log(e);

    var spielID = e.target.value;

    //ajax
    $.get('/spieler-table?spielID=' + spielID, function(data){

    //success data
    console.log(data);
    });
    });
    </script>
    @endsection

    @section('A')
    <h2>asd</h2>
    @endsection

现在,如果您要在一个视图中打印您的值,并希望在主服务器中加载另一个视图,例如sider bar,那么只需将其包括在内。

这是我的应用布局页面

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Dateneingabe</title>

    <link rel="stylesheet" href="/css/app.css">
    <script src="{{asset('/js/jquery-3.2.1.min.js')}}"></script>

</head>
<body>
    @yield('contentSpiel')
    @include('your_view_file_path')
</body>
</html>

答案 1 :(得分:0)

布局

<body>
    @yield('contentSpiel')
    @yield('A')
</body>

@stack('scripts')

contecontentSpiel.blade.php 查看(此视图应在操作中返回)

@extends('app')

@section('contentSpiel')

    <div class="form-group">
        ...
    </div>

@endsection

@push('scripts')
    <script>
        $('#spiele').on('change', function(e){
            ...
        });
    </script>
@endpush

@section('A')
   ...
@endsection

如果你想拥有多个刀片文件......你可以创建 sectionAForContentSpiel.blade.php 并移到此处A代码

@section('A')
   ...
@endsection

然后在 contecontentSpiel.blade.php

@include('sectionAForContentSpiel')

PS: 使用@stack('scripts')@push('scripts') - @endpush,您可以在页面底部包含脚本。

答案 2 :(得分:0)

我认为您需要更改您的应用布局页面,如:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Dateneingabe</title>

    <link rel="stylesheet" href="/css/app.css">
    <script src="{{asset('/js/jquery-3.2.1.min.js')}}"></script>

</head>
<body>
  <section class="contentSpiel">

    @yield('contentSpiel')

  </section>


  <section class="A">

    @yield('A')

  </section>

</body>
</html>

希望对你有所帮助!!!