Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 4-使用刀片模板扩展布局_Laravel_Laravel 4_Blade - Fatal编程技术网

Laravel 4-使用刀片模板扩展布局

Laravel 4-使用刀片模板扩展布局,laravel,laravel-4,blade,Laravel,Laravel 4,Blade,我刚刚安装了我的Laravel4.2应用程序,下面是一些关于身份验证的在线教程 教程告诉我要添加 protected $layout = "layouts.main"; @extends('layouts.main') 然后当调用视图时,像这样调用它 $this->layout->content = View::make('users.register'); 但是,如果我按照Laravel网站创建模板,它会告诉我添加 protected $layout = "layouts.m

我刚刚安装了我的Laravel4.2应用程序,下面是一些关于身份验证的在线教程

教程告诉我要添加

protected $layout = "layouts.main";
@extends('layouts.main')
然后当调用视图时,像这样调用它

$this->layout->content = View::make('users.register');
但是,如果我按照Laravel网站创建模板,它会告诉我添加

protected $layout = "layouts.main";
@extends('layouts.main')
在“我的用户/注册”视图的开头

如果我使用@extends调用,我需要为我在开始时添加的2位代码而烦恼吗

我真的很困惑


干杯

不,医生不会说你应该这么做。
您可以定义控制器布局(a),也可以返回扩展布局(b)的视图

A:控制器布局

/**
 * The layout that should be used for responses.
 */
protected $layout = 'layouts.master';

/**
 * Show the user profile.
 */
public function showProfile()
{
    $this->layout->content = View::make('user.profile');
}
B:视图扩展布局视图

// app/views/layout/master.blade.php
<html>
    <head>
        <title></title>
    </head>
    <body>
        <header>
            @yield('header')
        </header>
        <section>
            @yield('content')
        </section>
        <footer>
            @yield('footer')
        </footer>
    </body>
</html>

// app/views/profile.blade.php
@extends('layout/master')

@section('header')
    Header content here
@stop

@section('content')
    Master content here
    @if (Auth::user()->isAdmin)
        @include('admin-panel')
    @endif
@stop

@section('footer')
    Footer content here
@stop

// Controller
/**
 * Show the user profile.
 */
public function showProfile()
{
    return View::make('profile');
}    
//app/views/layout/master.blade.php
@收益率('header')
@产量(‘含量’)
@收益率('页脚')
//app/views/profile.blade.php
@扩展('布局/主')
@节(“标题”)
标题内容在这里
@停止
@节(“内容”)
主内容在这里
@if(Auth::user()->isAdmin)
@包括('管理面板')
@恩迪夫
@停止
@节(“页脚”)
页脚内容在这里
@停止
//控制器
/**
*显示用户配置文件。
*/
公共函数showProfile()
{
返回视图::make('profile');
}    

哦,好的。。。因此,根据编写代码的人,哪种方法都是正确的?或者以上两种方法中有更好的吗?我更喜欢第二种方法。它更灵活(例如,看一看编辑后的答案)完美。。。这就是我目前做这件事的方式。。。谢谢你的帮助!