视图无法正确显示。 Laravel

时间:2015-01-28 22:38:57

标签: php laravel routes blade

在我的Laravel项目中,我设置了一条路线来显示用户的个人资料页面。

Route::get('{id}', ['as' => 'profile', 'uses' => 'UsersController@show']);

这条路线的一切都很好。但是,我想将路线更改为

Route::get('profile/{id}', ['as' => 'profile', 'uses' => 'UsersController@show']);

当我这样做并导航到my.app:8000/profile/1我的CSS和html很好,但是我得到了一个破损的图像链接,我的jquery不再有效

我也试过

Route::get('/profile/{id}', ['as' => 'profile', 'uses' => 'UsersController@show']);

我正在使用src="{{URL::asset("images/users/xxxxxxx")}}"加载我的图片以及jquery

我的路线档案中没有其他地方我有profile/

的路线

不确定我能做什么。有人知道解决这个问题的方法吗?

编辑:

这是我的HTML:

<!doctype html>
<html>
    <head>
    <meta charset="utf-8">
            <!--Main Style Sheet-->
            {{ HTML::style('css/style.css'); }}
            <!-- JQuery -->
            <script src="/jquery/jquery-1.11.0.js"></script>
</head>

<body class="main-body">
<!-- this image works now that i added the leading / -->
<img src="{{ URL::asset("/images/users/{$user->id}/profilePictures/176thumb-{$user->profilePicture->url}") }}" alt="{{ $user->first_name }} {{ $user->last_name }} Profile Picture" width="176" height="176">

<!-- the jQuery For this is not working -->
<ul class="list-grid">
    <li>
        <div class="profile-example">
            <div class="add-box"></div>
        </div>
    </li>

</ul>

<!-- Include woodmark. This is the jquery plugin that isn't working -->
<script src="/jquery/jquery.wookmark.js"></script>
<!--Woodmark settings-->  
<script type="text/javascript">
    (function ($){
      $(function() {
        var $handler = $('.list-grid li');

        $handler.wookmark({
            // Prepare layout options.
             align: 'center',
             autoResize: true,
             comparator: null,
             container: $('html'),
             direction: undefined,
             ignoreInactiveItems: true,
             itemWidth: 560,
             fillEmptySpace: false,
             flexibleWidth: true,
             offset: 8,
             onLayoutChanged: undefined,
             outerOffset: 0,
             possibleFilters: [],
             resizeDelay: 50,
             verticalOffset: undefined
        });
      });
    })(jQuery);
  </script>

</body>
</html>

2 个答案:

答案 0 :(得分:1)

我认为这是你的JS /图像路径的问题,而不是Laravel。当您包含jQuery / images时,听起来就像是在使用相对路径,如下所示:

<script src="jquery/jquery.js>
<img src="img/image.jpg">

当您以这种方式调用资源时,如果您位于根级别,则会查找http://example.com/img/image.jpg,但如果您位于/profile,则会查找http://example.com/profile/img/image.jpg

如果在前面添加斜杠,它将始终从Web根目录开始路径:

<script src="/jquery/jquery.js>
<img src="/img/image.jpg">

如果您的CSS没问题,那么我怀疑您已经使用了绝对路径。

答案 1 :(得分:1)

我用过

{{ HTML::script('jquery/jquery.js'); }}

而不是

<script src="/jquery/jquery.js"></script>

现在一切正常

相关问题