I lose my bootstrap styles when passing variable (get) to route->Controller->View in Laravel 4

南笙酒味 提交于 2019-12-12 03:18:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!