【发布时间】:2017-04-07 01:58:39
【问题描述】:
当我传递 URL 参数(Laravel 5.4)时,我看到页面上的静态图像未加载(通常是损坏的占位符图像),但没有 URL 参数并使用完全相同的视图,它们加载正常。所以http://localhost/site/public/filmpage 显示图像但http://localhost/site/filmpage/batman 不显示图像(所有其他资产加载正常)。想知道这是为什么,以及如何解决?
我的 web.php 路由文件包含:
Route::get('filmpage', 'FilmController@filmpagetest');
Route::get('filmpage/{name}', 'FilmController@filmpage');
然后是控制器文件:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FilmController extends Controller
{
public function filmpage($name)
{
return view('filmpage',array('name' => $name));
}
public function filmpagetest()
{
return view('filmpage',array('name' => 'hello'));
}
}
我在我的 Win 7 64 位机器、PHP 5.6.24、Bitnami WAMP Stack 7.1.2 上运行 Laravel。
感谢您的任何建议。
【问题讨论】:
-
你能告诉我们你的看法吗?这将有助于解决问题。
-
view 只是刀片模板 (layout.blade.php) 中的一个非常简单的纯 HTML 文件,中间带有 @yield('content'),然后是一个单独的刀片模板页面内容。但是,对于工作页面和非工作页面,它使用相同的布局页面。
-
奇怪的是,当我在 Chrome 浏览器中查看呈现的页面源时,对于工作页面和非工作页面,两者中损坏图像的 HTML 链接都是:src="images/logo-small。 png" 但是,当我将鼠标悬停在链接上时,显示的实际完整图像路径(在 Chrome 中查看源窗口的底部)对于工作页面是 /localhost/site/public/images/logo-small.png,但对于不工作的一个(带参数)是:/localhost/site/public/filmpage/images/logo-small.png - 由于“filmpage”位而导致路径错误...
-
而不是
array('name' => $name)尝试return view('filmpage')->with('name',$name);并通过$name显示它。希望它会奏效!