doumao1887 2014-02-04 09:38
浏览 169
已采纳

Laravel PHP - 未传递给View的数组

I have a question about simple laravel code which is not working.

This is how the route looks:

Route::get('/', function()
{ 
    $chill = array(
            'heading' => 'Hello Laravel', 
            'body'    => 'This is totally awesome'
    );
    return View::make('test', $chill);
});

This is how the view looks in test.php:

{{ $heading }}

{{ $body }}

I don't understand why this is not working.

  • 写回答

1条回答 默认 最新

  • dongrenzheng1619 2014-02-04 09:42
    关注

    First of all you have to name your view

    test.blade.php
    

    if you want to use blade in your view.

    Then try this code here:

    Route::get('/', function()
    { 
    $chill = array(
    'heading' => 'Hello Laravel', 
    'body' => 'This is totally awesome'
     );
     return View::make('test')->with('chill', $chill);
     });
    

    Then use this in your view:

     {{ $chill['heading'] }}
    
     {{ $chill['body'] }}
    

    I hope that I don't have any minor errors but this should work now :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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