Php 控制器布局-如何成功返回包含修改内容的布局

Php 控制器布局-如何成功返回包含修改内容的布局,php,laravel,laravel-4,Php,Laravel,Laravel 4,我正在尝试设置并返回连接到控制器的布局。我可以成功设置@yeild(“content”)的内容,但无法同时设置和返回模板。我可以返回没有内容集的模板,也可以返回没有布局模板的内容集 master.blade.php <html> <head> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

我正在尝试设置并返回连接到控制器的布局。我可以成功设置@yeild(“content”)的内容,但无法同时设置和返回模板。我可以返回没有内容集的模板,也可以返回没有布局模板的内容集

master.blade.php

<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
...
public function show($uid, $lid, $hid)
{
    // $this->layout->content = View::make('hotspot.profile');
    $this->layout->content = 'a string';
    return $this->layout;
}
....
protected $layout = 'layouts.master';
...
public function show($uid, $lid, $hid)
{
    $this->layout->content = View::make('hotspot.profile');
}
...
I am a hotspot profile
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            {{ $content }}

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
@section('content')
I am a hotspot profile
@stop

@yield('content')和{{{$content}之间显然有区别

为了完成您试图完成的任务,您必须使用后一种方法在blade模板上声明变量内容

hospotcontroller.php

<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
...
public function show($uid, $lid, $hid)
{
    // $this->layout->content = View::make('hotspot.profile');
    $this->layout->content = 'a string';
    return $this->layout;
}
....
protected $layout = 'layouts.master';
...
public function show($uid, $lid, $hid)
{
    $this->layout->content = View::make('hotspot.profile');
}
...
I am a hotspot profile
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            {{ $content }}

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
@section('content')
I am a hotspot profile
@stop
hotspot.profile.blade.php

<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
...
public function show($uid, $lid, $hid)
{
    // $this->layout->content = View::make('hotspot.profile');
    $this->layout->content = 'a string';
    return $this->layout;
}
....
protected $layout = 'layouts.master';
...
public function show($uid, $lid, $hid)
{
    $this->layout->content = View::make('hotspot.profile');
}
...
I am a hotspot profile
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            {{ $content }}

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
@section('content')
I am a hotspot profile
@stop
master.blade.php

<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
...
public function show($uid, $lid, $hid)
{
    // $this->layout->content = View::make('hotspot.profile');
    $this->layout->content = 'a string';
    return $this->layout;
}
....
protected $layout = 'layouts.master';
...
public function show($uid, $lid, $hid)
{
    $this->layout->content = View::make('hotspot.profile');
}
...
I am a hotspot profile
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            {{ $content }}

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
<html>
    <head>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        @yield('styles')

    </head>
    <body>
        <div class="container">
            <h1>Google Earth project!</h1>
            <a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
            <hr>
            <h4>Content</h4>

            @yield('content')

        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

        @yield('scripts')

    </body>
</html>
@section('content')
I am a hotspot profile
@stop

尝试时发生了什么:返回视图::make('hotspot.profile');所需的模板成功渲染,但我定义的布局除外。出现一个占位符“我是一个配置文件模板!”字符串。您的PROFILE.blade.php以如下内容开头:@extends('layout\u path.layout\u file.blade.php')。我认为这不是一个好方法。看看我的答案,有几种不同的方法。