刀片视图中的 Laravel 未定义变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21808961/
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
laravel undefined variable in blade view
提问by Ray
I'm having trouble accessing a variable passed to a view in laravel blade.
我在访问传递给 laravel Blade 中的视图的变量时遇到问题。
I've had no problems before - in this case though I'm setting the variable and using a redirect as follows:
我以前没有遇到过任何问题 - 在这种情况下,虽然我正在设置变量并使用重定向,如下所示:
return Redirect::route('members.create')
->withInput()
->with('test1', 'Email address already exists.');
Then in my view i'm trying to echo out the result as follows:
然后在我看来,我试图将结果回显如下:
{{ (isset($test1) ? $test1 : "No Error" )}}
I know the error message exists as I can see it set in the profiler but any attempts to access $test1 gets an error: undefined variable
我知道错误消息存在,因为我可以在探查器中看到它设置,但任何访问 $test1 的尝试都会收到错误: undefined variable
I'm doing something very basic but obviously making a basic erro
我正在做一些非常基本的事情,但显然犯了一个基本的错误
Can someone help and tell me what is my schoolboy error!
有人可以帮忙告诉我我的小学生错误是什么!
Thank you
谢谢
采纳答案by Miroslav Trninic
Check for your variable using the static get
method in Session
.
使用中的静态get
方法检查您的变量Session
。
回答by Gaz_Edge
is that the exact code? As it doesn't add up - you can't get undefined variable
if you are checking isset($test1)
.
那是确切的代码吗?因为它没有加起来 -undefined variable
如果您正在检查isset($test1)
.
Do a search for $test1
in your view to see if you are trying to call it anywhere else without an isset
check.
$test1
在您的视图中搜索以查看您是否试图在没有isset
检查的情况下在其他任何地方调用它。
Also double check you haven't done something silly like written $test
instead of $test1
还要仔细检查你没有做一些愚蠢的事情,比如书面$test
而不是$test1