0

我正在努力学习 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')?即使您不想给我代码,也可以在我可以学习的地方或找到完整的文档来帮助我了解它是如何工作的。

感谢您的时间和帮助。

4

1 回答 1

3

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

我猜你的意思是调用View::make('home')which 将调用它自动扩展的刀片文件。

于 2013-06-06T23:37:47.640 回答