如何正确显示@yield()内容?

时间:2013-06-06 23:27:20

标签: php laravel laravel-4

我正在努力学习Laravel,虽然快速入门教会了我很多,但我一直没有任何问题,只是试图建立起来。

目前,我正在尝试使用文件public.blade.php作为我网站的主要公共布局。这是正常的。在该文件中,我正在尝试在其中显示@yield('title')@yield('content'),这是我遇到问题的部分。

app/views/public.blade.php内我有以下结构:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>@yield('title')</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
... 
... <!--layout code would be here-->
...
<div class="container">
        <div class="container">
        @yield('content')

        <hr />
        <footer>
            <p>&copy; Example Site 2013</p>
        </footer>
    </div> <!-- /container -->

app/views/home.blade.php内,我有以下内容:

@extends('public')

@section('title')
    @parent
    BootstrapCMS
@stop

@section('content')
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
    <h1>Welcome!</h1>
    <p>The goal of BootstrapCMS is to build a basic working content management system built around Twitter Bootstrap. This is primarily for personal learning purposes, as I look to better understand how content management systems function.</p>
    <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>

<!-- Example row of columns -->
<div class="row">
    <div class="span4">
        <h2>&Uuml;ber Secure</h2>
        <p>One of the main goals of this project, aside from basic learning, was to ensure that the design and implementation of all code was safe and secure. For this reason, passwords are securely encrypted using Blowfish, which prevents the password for being decrypted. For this reason, you can be sure that the passwords used with this system, even if leaked online, will be safe and secure.</p>
        <p><a class="btn" href="#">View details &raquo;</a></p>
    </div>
    <div class="span4">
        <h2>Heading</h2>
        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
        <p><a class="btn" href="#">View details &raquo;</a></p>
   </div>
    <div class="span4">
        <h2>Register Now!</h2>
        <form name="register" action="sections/register/take_register.php" method="POST">
            <div class="control-group">
                <label class="control-label" for="inputUsername">Username</label>
                <div class="controls">
                    <input type="text" class="span4" id="inputUsername" name="registerUsername" placeholder="Username" required>
                </div>
            </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
              <input type="password" class="span4" id="inputPassword" name="registerPassword" placeholder="Password" required>
            </div>
          </div>
          <div class="control-group">
            <div class="controls">
              <button type="submit" class="btn btn-primary">Register</button>
            </div>
          </div>
        </form>
    </div>
</div>
@stop

我知道我需要修改路线,所以我有app/routes.php

Route::get('/', function()
{
return View::make('public');
});

我还假设,可能不正确,我需要修改我的app/controllers/HomeController.php

public function showWelcome()
{
    $this->layout->content = View::make('public');
}

我知道这必须比我现在看起来更简单。为了让Laravel @yield('content')工作,我错过了什么?即使你不想给我代码,也只是在某个地方我可以学到这些或找到完整的文档来帮助我了解它是如何工作的。

感谢您的时间和帮助。

1 个答案:

答案 0 :(得分:3)

您正在调用模板视图(公共)并怀疑它是否填充了正确的内容?

我想你打算拨打View::make('home')来调用它自动扩展的刀片文件。