dongnan4571 2014-02-12 12:45
浏览 70
已采纳

未找到Laravel Blade布局视图[layout.default]

I've just started using "Laravel". But the code snippets isn't working.

inside my DemoController.php

<?php class DemoController extends BaseController
{   
    public $restful = true;

    public $layout = 'layout.default';  

    public function get_index() 
    {       
        $this->layout->title = 'laravelpage';

        $View = View::make('demo1.index' , array(
            'name'=>'Laravel user',              
            'age'=>'28',            
            'location'=>'dhaka'));

        $this->layout->content = $View; 
    }
}

and inside my index.blade.php

<!doctype html>

<html lang="en">

    <head>

        <meta charset="UTF-8"> 

        <title>{{ $title }}</title>
    </head>
    <body>  

        {{ $content }}

    </body>
</html>

my route is:

Route::controller('demo1','DemoController');

why it's showing this error? showing this error

How can I resolve it?

  • 写回答

2条回答 默认 最新

  • douyue2313 2014-02-12 12:56
    关注

    You mean Blade Layout ?

    First,instead of get_index, use just index method name in you controller. Second, try to use resourceful controllers - mapping from your route to you domain logic will be much more clear, and you'll have whole resource generated. For that purpose use great laravel generator package.

    Third, I dont see any connection between your blade variables and provided array ?

    Using generators is optional, just a good practice.

    Better solution is:

    public function index()
    {
    
        $my_array ["title"=>"some_title","content"=>"some_content"];
        return View::make("my_view")->with("my_array",$my_array); 
        //or
        return View::make("my_view",compact("my_array"));
    }
    

    UPDATE:

    Besides other things that can go wrong in you app (permissions,laravel version...), you need to follow very basic pattern in order this to work:

    Create a new route with:

    Route::get("demo1","DemoController@index");
    

    Create a new view (index.blade.php file) in your views folder (or subfolder).

    Create a new controller:

    class DemoController extends BaseController{
    
        public function index()
        {
            $my_array = ["title"=>"some_title","content"=>"some_content"];
            return View::make("index")->with("my_array",$my_array);
    
        }
    }
    

    And in index.blade.php you can put something like:

    {{$title}}
    {{$content}}
    

    Now go to browser and you should see title and content, after refresh. I guess your server settings are right.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作