laravel file_get_contents of a route get no response

微笑、不失礼 提交于 2019-12-22 10:58:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!