问题
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::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/1 this is right.
But this does not work. I get no response, and the php artisan serve breaks. Why? What is wrong here?
回答1:
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.
You can tell because the your view isn't stored in the folder de/playlist/raw, it's stored in 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.
来源:https://stackoverflow.com/questions/27945487/laravel-file-get-contents-of-a-route-get-no-response