问题
I am integrating a Bootstrap template to laravel 4 and I am having an issue when passing variables through the GET method. My final View renders without any style applied.
Let's say I have a link like this:
<a href="{{url('offer')}}">Oferta 2015</a>
caught by a route like this>
Route::get('offer','HomeController@showOffer');
And the controller like:
public function showOffer()
{
$Cursos = Curso::paginate(10);
return View::make('cursos.offer')->with('cursos',$Cursos);
}
That works just fine (the master view extended by the offer view renders perfectly).
My issue happens when I try to pass a variable like this>
link:<a href="{{url('offer/2015')}}">Oferta 2015</a>
route: Route::get('offer/2015',array('myYear'=>'year','uses'=>'HomeController@showOffer'));
What happens here is that I get the View displayed, but with no styles at all. Just like when you get rid of the "link href ..." in the header.
Any idea would be highly appreciated, thanks.
回答1:
Currently you have defined all your include paths relative. So when the directory level in the URL changes the styles don't get found. You should use the helpers Laravel provides to generate a full URL.
There's asset()
<link href="{{ asset('assets/css/bootstrap.min.css') }}" rel="stylesheet">
Or even a helper to create the full link
tag for including
{{ HTML::style('assets/css/bootstrap.min.css') }}
(And there's one for javascript files too)
{{ HTML::script('assets/js/script.js') }}
来源:https://stackoverflow.com/questions/27473626/i-lose-my-bootstrap-styles-when-passing-variable-get-to-route-controller-vie