Here is my controller code:
$view = View::make('homepage');
$loglink = URL::route('account.login');
$view->loglink = $loglink;
return $view;
Here is how I recv it in view:
<a href="{{ $loglink }}" class="red">
I get an error saying:
Undefined variable: loglink (View:
C:\BottleBookings\server\app\views\partials\header.blade.php)
Any problem with the way I am sending or recving it?
Thats not how view creation works. Just return
your view and pass the variables you want to use with the with()
function in the same command. Create your view like this:
$loglink = URL::route('account.login');
return View::make('homepage')->with('loglink', $loglink);
Or even shorter:
return View::make('homepage')->with('loglink', URL::route('account.login'));
Also, you don't really have to pass the link URLs, it's perfectly fine to generate them where they are needed in the view:
<a href="{{ URL::route('account.login') }}" class="red">
why you complicate. just put the datas in array and pass it to view.
Controller
$data['loglink'] = URL::route('account.login');
return View::make('homepage',$data);
p.s. your loglink variable will be available to only homepage
view. NOT on header page.
if you want to pass the loglink to header, then you have to pass it as View::composer
or View::share
or where you are including the file. any one of the three will do.