duanchi4184
2014-01-31 15:08
浏览 85
已采纳

无法将路径中的变量传递给laravel 4中的视图

I'm trying to learn Laravel 4 and reading the book called Laravel: code bright

I'm trying to pass array data from routes to view but I get this error

ErrorException Undefined variable: squirrel

Codes are like these. Same as in the book.

url localhost/test

routes.php

<?php
    Route::get('/{squirrel}', function() {

        $data['squirrel'] = $squirrel;

        return View::make('simple', $data);
    });
?>

simple.php

<!DOCTYPE html>
    <html lang="eng">
    <head>
            <meta charset="UTF-8">
            <title>Views!</title>
    </head>
    <body>
            <p>I  wish I were a <?php echo $squirrel; ?> squirrel!</p>
    </body>
    </html>

图片转代码服务由CSDN问答提供 功能建议

我正在尝试学习Laravel 4并阅读名为Laravel的书:代码明亮 \ n

我正在尝试将路径中的数组数据传递给视图,但是我收到此错误

ErrorException 未定义的变量:squirrel

代码就像这些。 与本书相同。

url localhost / test

routes.php

 &lt  ;?php 
 Route :: get('/ {squirrel}',function(){
 
 $ data ['squirrel'] = $ squirrel; 
 
返回View :: make('simple',  $ data); 
}); 
?&gt; 
   
 
 

simple.php

 &lt;  !DOCTYPE html&gt; 
&lt; html lang =“eng”&gt; 
&lt; head&gt; 
&lt; meta charset =“UTF-8”&gt; 
&lt; title&gt; Views!&lt; / title&gt; \  n&lt; / head&gt; 
&lt; body&gt; 
&lt; p&gt;我希望我是一个&lt;?php echo $ squirrel;  ?&GT; 松鼠!&lt; / p&gt; 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题