Php Laravel @yield或@section无效

问题描述 投票:1回答:2

我的收益或部分不起作用是我的代码我想我已经遵循所有规则。你可以看到我想调用home.blade.php我将它命名为@section('content-page')并使用yield('content-page')将其命名为main.blade.php但似乎产量或部分不起作用。这是我的代码如下:

home.blade.php

@extends('layouts.masters.main')

@section('page-content')

@include('layouts.partials.nav')

<div id="myCarousel" class="carousel slide" data-ride="carousel">
              <!-- Indicators -->
            <ol class="carousel-indicators">
                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#myCarousel" data-slide-to="1"></li>
                <li data-target="#myCarousel" data-slide-to="2"></li>
                <li data-target="#myCarousel" data-slide-to="3"></li>
            </ol>

              <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <div class="item active">
                    <img src="../custom/image/image-slider/1.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/2.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/3.jpg">
                </div>

                <div class="item">
                    <img src="../custom/image/image-slider/4.jpg">
                </div>
            </div>

              <!-- Left and right controls -->
            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>

        <div id="news-container">
            <h2>News</h2>
            <div class="strike">
                <span>Latest</span>
            </div>
            <div class="container">
                <div class="row">
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/3.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/2.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                  <div class="col-sm-4">
                        <figure>
                            <img src="../custom/image/image-slider/1.jpg" height="300px;" width="100px;">

                            <figcaption>
                                <h3>I love this title!</h3>

                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
                                eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                                <p><a href="../news/new.php">Read More</a></p>
                            </figcaption>
                        </figure>
                  </div>
                </div>
            </div>
        </div>  

        <div id="about-container">
            <h2>About</h2>
            <div class="strike">
                <span>Our Story</span>
            </div>
                <p>
                    There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form,

                </p>
        </div>  

        <div id="contact-container" style="background-color: whitesmoke;">
        <h2>Contact</h2>

        <div class="strike">
                <span>Our Contact</span>
        </div>
            <div class="container" style="padding: 35px;">
                <div class="row">
                    <div class="col-sm-6" style="background-color: whitesmoke; padding: 10px;">  
                        <form>
                          <div class="form-group">
                            <label for="name">Name:</label>
                            <input type="name" class="form-control" id="name" required id="name-textfield">
                          </div>
                          <div class="form-group">
                            <label for="email">Email:</label>
                            <input type="email" class="form-control" id="email" required id="email-textfield">
                          </div>
                          <div class="form-group">
                            <label for="message">Message:</label>
                            <textarea type="message" class="form-control" rows="4" cols="50" required id="message-textarea">
                            </textarea>
                          </div>
                          <button type="submit" class="btn btn-default">Send</button>
                        </form>         
                    </div>
                    <div class="col-sm-6" style="padding: 10px;">  
                          <div class="form-group">
                            <label >Address</label>
                            <p>O4F Vasile milea Blvd.Afi Park 2 Bucharest 6 Romania 061344</p>
                          </div>    
                          <div class="form-group">
                            <label >Phone</label>
                            <p> +46 (0)31 33 35 000</p>
                          </div>    
                          <div class="form-group">
                            <label >Email</label>
                            <p>[email protected]</p>
                          </div>    
                    </div>
                </div>  
            </div>  
        </div>  

@include('layouts.partials.footer')

@stop

路线代码

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', [
    'as' => 'home',
    'uses' => 'PagesController@home'
]);

PageController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PagesController extends Controller
{
    public function home()
    {
        return view('layouts.masters.main'); 
    }
}

最后我的main.blade.php

<!DOCTYPE html>
<html>
    <head>
        <title>

            Forester | Home

        </title>

            <link rel="stylesheet" href="../custom/bootstrap/css/bootstrap.min.css">
            <!-- <script src="../HCI/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script> -->
            <!-- jQuery library -->
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

            <!-- Latest compiled JavaScript -->
            <script src="../custom/bootstrap/js/bootstrap.min.js"></script>

            <link rel="stylesheet" type="text/css" href="../custom/css/css.css">

    </head>

    <body>

        <div class="col-xs-12">

            @yield('page-content')

        </div>

    </body>

</html>
php laravel
2个回答
1
投票

不确定这是不是问题,但你错过了@endsection文件末尾的home.blade.php标签


1
投票

在控制器中,必须将返回值更改为“layouts.masters.home”(而不是“layouts.masters.main”)。

在您的视图目录中,您必须有一个名为“masters”的目录,在其中必须有“main.blade.php”和“home.blade.php”

© www.soinside.com 2019 - 2024. All rights reserved.