laravel 使用来自控制器的未定义常量来查看
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21892572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use of undefined constant from controller to view
提问by RSM
I am using laravel 4 with blade templating on the views as is per standard.
我按照标准在视图上使用带有刀片模板的 laravel 4。
I am simply testing how to pass data from the controller to the view. I just want my view to output 'testing'.
我只是在测试如何将数据从控制器传递到视图。我只希望我的视图输出“测试”。
Route:
路线:
Route::controller('/blog', 'BlogController');
Controller:
控制器:
class BlogController extends BaseController {
public function getIndex()
{
return View::make('blog')->with('test', 'testing');
}
}
Cut down version of view:
精简版视图:
<div class="col-lg-12 text-center">
<h1>Blog</h1>
{{test}}
</div>
According to the documentation I have read, I may have read it incorrectly, this should work. However, I am getting the error message:
根据我读过的文档,我可能读错了,这应该有效。但是,我收到错误消息:
Use of undefined constant test - assumed 'test'
How can I fix this? What have I done wrong?
我怎样才能解决这个问题?我做错了什么?
回答by AbraCadaver
I'm pretty sure you want $
:
我很确定你想要$
:
{{$test}}
{{$test}}
or
或者
{{{$test}}}
{{{$test}}}
回答by RSM
It should be:
它应该是:
<div class="col-lg-12 text-center">
<h1>Blog</h1>
{{$test}}
You are receiving this error because you are trying to use a constant which doesn't exists.
您收到此错误是因为您正在尝试使用不存在的常量。