路由的 laravel file_get_contents 没有响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27945487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel file_get_contents of a route get no response
提问by goldlife
I have a route:
我有一条路线:
Route::group(array('prefix' => 'playlist'), function()
{
Route::get('raw/{id}', array('as'=>'rawPlaylist', 'uses'=>'PlaylistsController@raw'));
});
When I open the URL:
当我打开网址时:
http://localhost:8000/playlist/raw/1
Everything is fine and the page will load and show me the view.
一切都很好,页面将加载并向我显示视图。
In a controller I get the URL:
在控制器中,我得到了 URL:
$url = URL::route('rawPlaylist', 1);
The problem:I want read the view and store the whole view into a variable:
问题:我想读取视图并将整个视图存储到一个变量中:
$html = file_get_contents($url);
echo $url is http://localhost:8000/playlist/raw/1this is right.
echo $url 是http://localhost:8000/playlist/raw/1这是正确的。
But this does not work. I get no response, and the php artisan serve breaks. Why? What is wrong here?
但这不起作用。我没有得到任何回应,php artisan 服务中断。为什么?这里有什么问题?
回答by Chris Schmitz
You're not able to use file_get_contents
on a laravel route because the laravel routes aren't actual paths to the view file.
您无法file_get_contents
在 laravel 路由上使用,因为 laravel 路由不是视图文件的实际路径。
You can tell because the your view isn't stored in the folder de/playlist/raw
, it's stored in app/views/pathtoyourrawview
.
您可以判断,因为您的视图未存储在文件夹中de/playlist/raw
,而是存储在app/views/pathtoyourrawview
.
I haven't tried it, but I'm assuming you can capture your view's code into a variable by using:
我还没有尝试过,但我假设您可以使用以下方法将视图的代码捕获到变量中:
$html = View::make('rawPlaylist')->render();
Basically, instead of returning your View::make
result you write it to a variable.
基本上,不是返回View::make
结果,而是将其写入变量。