[英]Laravel 4 Undefined variable errors
Getting *ErrorException' with message 'Undefined variable: textareaBBCode*
*ErrorException' with message 'Undefined variable: textareaBBCode*
I do assign a value in the Controller before the foreach loop 我确实在foreach循环之前在Controller中分配了一个值
$textareaBBCode = "";
$textareaHtmlCode = "";
foreach($results as $result){
$textareaBBCode .= $result->bbCode.' ';
$textareaHtmlCode .= $result->htmlCode.' ';
and use ->with to send it to the view 并使用-> with将其发送到视图
return View::make('layouts/show')
->with('results', $results)
->with('textareaBBCode', $textareaBBCode)
->with('textareaHtmlCode', $textareaHtmlCode);
Then in the view I have attempted to remedy the error with if(Session) 然后在视图中,我尝试使用if(Session)纠正错误
@extends('layouts.master')
@section('display')
@if(Session::has('textareaBBCode'))
{{Session::get('textareaBBCode')}}
@endif
@if(Session::has('textareahtmlCode'))
{{Session::get('textareahtmlCode')}}
@endif
<textarea id='textareaBBCode'>{{$textareaBBCode}}</textarea>
<textarea id='textareahtmlCode'>{{$textareaHtmlCode}}</textarea>
But the error persists. 但是错误仍然存在。 I have searched for a few hours now and would really like some help thanks.
我已经搜索了几个小时,非常感谢您的帮助。
You don't need to use sessions to access the variables. 您不需要使用会话来访问变量。 You are just able to use $textareaBBCode in the view.
您仅可以在视图中使用$ textareaBBCode。
See how the $name variable is accessed in this example from the docs: http://laravel.com/docs/4.2/responses#views 在此示例中,了解如何从docs访问$ name变量: http : //laravel.com/docs/4.2/responses#views
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.