0

Getting *ErrorException' with message 'Undefined variable: textareaBBCode*

I do assign a value in the Controller before the foreach loop

   $textareaBBCode = "";
   $textareaHtmlCode = "";
   foreach($results as $result){

   $textareaBBCode .= $result->bbCode.' ';
   $textareaHtmlCode .= $result->htmlCode.' ';

and use ->with to send it to the view

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)

@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.

1 Answer 1

1

You don't need to use sessions to access the variables. You are just able to use $textareaBBCode in the view.

See how the $name variable is accessed in this example from the docs: http://laravel.com/docs/4.2/responses#views

Sign up to request clarification or add additional context in comments.

3 Comments

To clarify: when returning a redirect, with() does indeed use session flashing. But when returning a view, with() binds to variables as you mention.
Yes - before the 'Undefined variable' error appeared I wasn't using sessions and just used the method in the docs. In fact there were no errors until I put some jQuery script in the upload form view. But how that could have impacted on this particular error I haven't the foggiest - the only difference is that the jQuery now handles the upload submit to the Controller. Everything works fine until we get to this error with the undefined variable. Would it help if I posted the jQuery too?
Metarzan, off the top of my head I can't think of any issues that would cause. Are there any console errors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.