Php Laravel-加载公共页眉和页脚以查看
我是laravel的新手,我正在尝试在公共模板中从controller加载页眉、页脚和视图文件,并在视图文件中显示controller中的数据。但我发现错误Php Laravel-加载公共页眉和页脚以查看,php,laravel,laravel-5.1,Php,Laravel,Laravel 5.1,我是laravel的新手,我正在尝试在公共模板中从controller加载页眉、页脚和视图文件,并在视图文件中显示controller中的数据。但我发现错误视图['admin.dashboard']未找到。 仪表板文件位于视图内的管理文件夹中 控制器 namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller;
视图['admin.dashboard']未找到。
仪表板文件位于视图内的管理文件夹中
控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class common extends Controller
{
public function login()
{
$data['title'] = 'Dashboard';
$data['template'] = 'admin/dashboard';
return view('common_template', compact('data'));
}
}
通用模板.刀片视图
<?php echo View::make('includes/header'); ?>
<?php echo $template = "'".$data['template']."'";
echo View::make($template); ?>
<?php echo View::make('includes/footer'); ?>
<p><?php echo $data['title']; ?></p> //printing the data from the controller
@include('includes.header')
@yield('content')
@include('includes.footer')
@extends('common_template')
@section('content')
{{$data['title']}}
@endsection
请帮我度过难关。感谢要将刀片模板包含到另一个模板中,请使用: 或 此外,请检查视图的名称是否正确,是否位于正确的目录中:
resources/views/admin/dashboard.blade.php
首先,您的代码需要按照laravel刀片代码标准进行更正。请尝试以下代码:
通用模板.刀片视图
<?php echo View::make('includes/header'); ?>
<?php echo $template = "'".$data['template']."'";
echo View::make($template); ?>
<?php echo View::make('includes/footer'); ?>
<p><?php echo $data['title']; ?></p> //printing the data from the controller
@include('includes.header')
@yield('content')
@include('includes.footer')
@extends('common_template')
@section('content')
{{$data['title']}}
@endsection
dashboard.blade视图
<?php echo View::make('includes/header'); ?>
<?php echo $template = "'".$data['template']."'";
echo View::make($template); ?>
<?php echo View::make('includes/footer'); ?>
<p><?php echo $data['title']; ?></p> //printing the data from the controller
@include('includes.header')
@yield('content')
@include('includes.footer')
@extends('common_template')
@section('content')
{{$data['title']}}
@endsection
要将刀片模板包括到另一个模板中,
layouts/index.blade.php
{{$title}}//动态标题
@堆栈('css')//内部css
@include('../website/layouts/header')//include header
@yield('content')//包含内容
@include('../website/layouts/footer')//包含页脚
@堆栈('js')//内部js
layouts/footer.blade.php
// footer code
<h1>This area for footer code
// headercode
<h1>This area for headercode
<?php $title = "dynamic title"; ?> //title
@extends('layouts/index') //include index page
@Push('css') // this is for internal js
*{
color:black;
}
@endpush
@section('content') //section for content
This area for home page content
@stop // content ended
@Push('js') // this is for internal js
<script>
$(document).ready(function(){
var loggedIn={!! json_encode(Auth::check()) !!};
$('.send').click(function() {
if(!loggedIn){
moda.style.display = "block";
return false;
}
});
});
@endpush
//页脚代码
此区域用于输入页脚代码
layouts/header.blade.php
// footer code
<h1>This area for footer code
// headercode
<h1>This area for headercode
<?php $title = "dynamic title"; ?> //title
@extends('layouts/index') //include index page
@Push('css') // this is for internal js
*{
color:black;
}
@endpush
@section('content') //section for content
This area for home page content
@stop // content ended
@Push('js') // this is for internal js
<script>
$(document).ready(function(){
var loggedIn={!! json_encode(Auth::check()) !!};
$('.send').click(function() {
if(!loggedIn){
moda.style.display = "block";
return false;
}
});
});
@endpush
//头代码
此区域用于headercode
/home.blade.php
// footer code
<h1>This area for footer code
// headercode
<h1>This area for headercode
<?php $title = "dynamic title"; ?> //title
@extends('layouts/index') //include index page
@Push('css') // this is for internal js
*{
color:black;
}
@endpush
@section('content') //section for content
This area for home page content
@stop // content ended
@Push('js') // this is for internal js
<script>
$(document).ready(function(){
var loggedIn={!! json_encode(Auth::check()) !!};
$('.send').click(function() {
if(!loggedIn){
moda.style.display = "block";
return false;
}
});
});
@endpush
//标题
@扩展('layouts/index')//包含索引页
@Push('css')//这是用于内部js的
*{
颜色:黑色;
}
@端推
@section('content')//用于内容的节
此区域用于显示主页内容
@停止//内容已结束
@Push('js')//这是用于内部js的
$(文档).ready(函数(){
var loggedIn={!!json_encode(Auth::check())!!};
$('.send')。单击(函数(){
如果(!loggedIn){
moda.style.display=“块”;
返回false;
}
});
});
@端推
您没有使用刀片式发动机。使用{{$your variable}}
在视图中显示数据。这是正确答案。与其同时包含页眉和页脚,还不如扩展模板。