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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?