dongmi1872 2016-12-10 10:25
浏览 257
已采纳

Laravel - 加载公共页眉和页脚以查看

I am new to laravel and I am trying to load header, footer and the view file from controller in a common template and display the data from controller in the view file. But I am get error View ['admin.dashboard'] not found.

The dashboard file is present in admin folder inside views

controller

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'));

   }
}

common_template.blade View

<?php echo View::make('includes/header'); ?>

<?php echo $template = "'".$data['template']."'"; 
echo View::make($template); ?> 
<?php echo View::make('includes/footer'); ?>

When I add 'admin/dashboard' instead of $data['template'] directly in $template it loads the dashboard file whereas it doesnt load when i pass it as string from controller.

dashboard.blade view

<p><?php echo $data['title']; ?></p> //printing the data from the controller

Kindly help me get through this. Thanks

  • 写回答

3条回答 默认 最新

  • dousikuai5417 2016-12-10 10:32
    关注

    To include blade template into another template, use @include:

    @include('admin.dashboard')
    

    Or

    @include($data['template']) // This should be the name of template, like 'admin.dashboard', but not path
    

    Also, check if view has correct name and is in right directory:

    resources/views/admin/dashboard.blade.php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog