I'm slowly starting to come to grip with Laravel but keep having little issues doing basic things.
So this is what I have at the moment
A function and a function that is called by my route
both in my webcontroller.php
// Function for printing out copyright year
function copyright_info($begin_year = NULL)
{
date_default_timezone_set('Europe/London');
if(empty($begin_year) || $begin_year == date('Y'))
echo date('Y');
else
echo $begin_year." - ".date('Y');
}
// function being called by route.php to get Restaurant Page
public function restaurant () {
$cookie = Cookie::get("basket");
return view('pages.restaurant', ['basket' => $cookie]);
}
Now all the first function does is print out something like 2013-2015
once the year is provided.
So I should be able to do something like this
public function restaurant () {
// use the function and get copyright year
$year = copyright_info('2013')
$cookie = Cookie::get("basket");
// pass data to the view including the year we just created
return view('pages.restaurant', ['basket' => $cookie, 'year' => $year]);
}
Now in my restaurant.blade.php
file, I'm including my footer in my includes
folder that is generic to all my pages like this @include('includes.footer')
. Now the footer is what actually contains a div
that requires the $year
I have passed to the restaurant
view. in my footer.blade.php
I have this
<p style="font-size: 0.9rem">Copyright © {{ $year }} | xxx.com Limited</p>
Now I would assume that when I pass data to restaurant
and footer
is included in restaurant
the data will apply to footer
when it gets included in restaurant
but that doesn't happpen.
After a lot of testing, I have now found out that my function doesn't produce any data at all. This is not because the function doesn't work also because in normal PHP
it does
Any guidance appreciated
尝试将$ year从restaurant.blade传递到footer.blade
@include('includes.footer', ['year'=>$year])
So I figured it out.
return
something. From the question you can see that my function
uses echo
Hope this helps someone in the future.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.