Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

hello people here is my code below for controller

$siteinformation = DB::table('siteinformation')->where('Site',$myarr[0]['site'])->select()->get();

print_R($siteinformation); will display

Array ( [0] => stdClass Object ( [Site] => site1 [Nickname] => friend [ProgramID] => 1 [CreateDateTime] => 2014-06-03 18:05:39 ) )

I am trying to pass it to view

return Redirect::to('sbs_site')->with('siteinformation',$siteinformation);

In my view i have...

@if(Session::has('siteinformation'))
@foreach ($siteinformation as $key => $value) 

{{ $value->Nickname }}

@endforeach
    @endif

Iam gettng an error Undefined variable: siteinformation

my route file contains... Route::post('sbs_site', array('uses' => 'myController@sys_config'));

what could be the problem??

share|improve this question
up vote 2 down vote accepted

I think you don't need to redirect; probably you are doing it wrong, instead you should pass the data to the view directly using something like this:

$siteinformation = DB::table('siteinformation')
                     ->where('Site',$myarr[0]['site'])
                     ->get();
// View Name: "sbs_site.blade.php"
return View::make('sbs_site')->with('siteinformation', $siteinformation);

Then in the view:

@foreach ($siteinformation as $value) 

    {{ $value->Site }}
    {{ $value->Nickname }}

@endforeach

But if your really need to use a redirect then you may do it like this:

// Route Is: "sbs_site"
return Redirect::to('sbs_site')->with('siteinformation', $siteinformation);

Then in your view:

@if(Session::has('siteinformation'))

    @foreach (Session::get('siteinformation') as $value) 

    {{ $value->Site }}
    {{ $value->Nickname}}

    @endforeach

@endif
share|improve this answer
    
even i want to do without redirecting, but its not working , i get an error Undefined variable: siteinformation – Friend Jun 4 '14 at 5:23
    
It should work if you load the view directly from the controller, what URI you are using to see the page and what is your view name? – The Alpha Jun 4 '14 at 5:27
    
your second answer is exactly same as mine,ya that worked...` view:make` did not work.. uri =http://localhost/sup/public/sbs_site sbs_site is my view name... i get an error message on the uri page... – Friend Jun 4 '14 at 5:29
    
It must work if you did everything properly, check it again. There is nothing very complex, it's a very simple task in Laravel. – The Alpha Jun 4 '14 at 5:34
    
@ WereWolf - The Alpha Thank you...i hope it does.. let me check again... – Friend Jun 4 '14 at 5:36

This worked for me...

in view

     @if(Session::has('siteinformation'))

     @foreach (Session::get('siteinformation')as $key => $value) 

     {{ $value->Nickname}}

      @endforeach

     @endif

In controller

    return Redirect::to('sbs_site')->with('siteinformation',$siteinformation);
share|improve this answer

Your view file is not getting session set if(Session::has('siteinformation')), because you did not set session in your controller. You set in your controller 'siteinformation' as a normal variable. If you want to set session, instead of this.

Redirect::to('sbs_site')->with('siteinformation',$urserializedobj);

Do this

Session::put('siteinformation',$urserializedobj);
Redirect::to('sbs_site');

OR

Simply don't check session in your view instead of this

if(Session::has('siteinformation'))

Just do this

if (!empty($siteinformation)) :
share|improve this answer

I don't know why u are redirecting to pass it to the view

return View::make('yourview',array('siteinformation'=>$siteinformation));

This will do the trick if you can make the view directly from the controller BUT if u need to redirect than i suppose you can serialize your array or change it to json first because the with function passes the data as flash so only strings

$urserializedobj = $siteinformation.toJson();//if this doesn't work try serealizing
return Redirect::to('sbs_site')->with('siteinformation',$urserializedobj );

now in your view you can do this

@if(Session::has('siteinformation'))
 $siteInformation = json_decode(Session::get('siteinformation'));
 @foreach ($siteinformation as $key => $value) 

 {{ $value->Nickname }}

 @endforeach
@endif
share|improve this answer
    
i tried to your first solution but did not work it will make a view but does hold any variable values.. :( let me try your second solution... – Friend Jun 4 '14 at 4:08
    
second solution,I am getting an error Call to a member function toJson() on a non-object – Friend Jun 4 '14 at 4:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.