2015-02-09 49 views
0

路线Laravel:脚本和布局图像源不工作的网址前缀

Route::group(array('before' => 'guest'), function() 
{ 
    // home 
    Route::get('/', array('uses' => '[email protected]', 'as' => 'home')); 
    Route::get('home', array('uses' => '[email protected]', 'as' => 'home')); 
    Route::get('/user/create', array('uses' => '[email protected]', 'as' =>'getCreate')); 
    Route::get('/user/login', array('uses' => '[email protected]', 'as' =>'getLogin')); 
    Route::group(array('before' => 'csrf'), function() 
     { 
      Route::post('/user/create', array('uses' => '[email protected]', 'as' => 'postCreate')); 
      Route::post('/user/login', array('uses' => '[email protected]', 'as' => 'postLogin')); 
     }); 

}); 

我想在我的master.blade.php文件添加链接脚本文件,如下

<link rel="stylesheet" href="css/bootstrap.min.css"> 

这将在URL正常工作:

本地主机/公共

,但如果我想查看我的网页/用户/登录,然后启动脚本是不工作... 但是,如果我指定的环节

<link rel="stylesheet" href="../css/bootstrap.min.css"> 

则引导脚本会在适当/用户/登录工作 但它会在链接没有前缀

+0

张贴在这里装载引导CSS和JS – Laurence 2015-02-09 10:46:18

+0

重写你的问题..... – itachi 2015-02-09 10:57:47

回答

0

当加载这样的样式表无法正常工作:

<link rel="stylesheet" href="css/bootstrap.min.css"> 

样式表的链接附加到浏览器的当前网址。因此,对于http://somedomain.com/,变成http://somedomain.com/css/bootstrap.min.css - 但http://somedomain.com/somefolder/,变成http://somedomain.com/somefolder/css/bootstrap.min.css

当你这样做然而,这,:

<link rel="stylesheet" href="../css/bootstrap.min.css"> 

什么你说的是“走一级目录,然后附加链接” 。

你想要什么大概是这样的:

<link rel="stylesheet" href="/css/bootstrap.min.css"> 

/在开始的时候说:“去你的域的根”,然后将其附加的样式表链接。

0

在Laravel中,您必须添加下面的CSS和JS。你正在使用刀片!

{{ HTML::style('css/default.min.css'); }} <!-- For CSS --> 

{{ HTML::script('js/scripts.min.js'); }} <!-- For JS --> 

按照我的示例,请确保css存在于css文件夹中,并且js存在于js文件夹中。

public/css/default.min.css 

public/js/scripts.min.js 
+0

,它正在你的视图代码...谢谢 – manoos 2015-02-13 06:07:46

+0

有没有什么帮助你,请接受的答案。谢谢 – Surya 2015-02-13 06:58:08