laravel怎么传html页面,laravel 5.3如何使用函数在视图中呈现页面的html内容(laravel 5.3 how to render html content of a page i...

laravel 5.3如何使用函数在视图中呈现页面的html内容(laravel 5.3 how to render html content of a page in a view with a function)

我正面临渲染问题...在我的product.blade.php中我想在页面的一部分中显示来自没有iframe的外部源的html内容。 我想拨打电话:

{!! View::make('pages.viewer', ['docUrl' => url('get-DocHtml/' . $primaryAttachment->id)]) !!}

在我的路线:

Route::get('get-DocHtml/{id}', 'PagesController@getDocHtml');

在PagesController.php中:

public function getDocHtml($id){

$attachment = Attachment::find($id);

$filepath = Storage::disk('S3')->url($attachment->filename.'/test.html');

return \Response::make(file_get_contents($filePath), 200, [ 'Content-Type' => 'text/html; charset=utf-8' ]);

}

我不知道如何在viewer.blade.php中进行渲染,或者直接在我的product.blade.php中进行渲染,就像函数的all一样直接渲染它...

有人知道如何渲染它(没有帮助者)吗?

谢谢你的帮助。

I am facing a rendering problem... in my product.blade.php I would like to show in a part of the page the html content from an external source without iframe. I want to make a call like :

{!! View::make('pages.viewer', ['docUrl' => url('get-DocHtml/' . $primaryAttachment->id)]) !!}

In my route :

Route::get('get-DocHtml/{id}', 'PagesController@getDocHtml');

In PagesController.php :

public function getDocHtml($id){

$attachment = Attachment::find($id);

$filepath = Storage::disk('S3')->url($attachment->filename.'/test.html');

return \Response::make(file_get_contents($filePath), 200, [ 'Content-Type' => 'text/html; charset=utf-8' ]);

}

I don't know how to make it render in viewer.blade.php or directly in my product.blade.php like a all to the function and render it directly...

Is someone has any idea how to render it (without helpers) ?

Thanks for your help.

原文:https://stackoverflow.com/questions/40963383

更新时间:2020-02-07 09:26

最满意答案

你为什么不通过

file_get_contents($filePath)

作为变量来查看?

你的方法getDocHtml应该以这种方式返回视图:

return view('viewer')->with([

'external' => file_get_contents($filePath)

]);

然后你可以通过传递$external变量做任何事情

Why don't you pass

file_get_contents($filePath)

as variable to view?

your method getDocHtml should return view in that way:

return view('viewer')->with([

'external' => file_get_contents($filePath)

]);

Then you can do anything with passed $external variable

相关问答

您可以使用视图编辑器,以便在加载提供程序时不会立即执行查询。 取而代之的是注册视图编辑器,并且只有当视图实际需要时才会执行查询。 阅读更多: https : //laravel.com/docs/5.2/views#view-composers You can use view composer so your query is not executed instantly when provider is loaded. Instead register view composer, and q

...

你应该设置一个新的功能和路线,在执行逻辑之后将用户重定向到正确的页面: public function home()

{

return view('home_done');

}

public function step_3()

{

// do something and redirect

return redirect('home_done#3rdPage');

}

使用view不起作用,因为您正在加载文件,而不是页面。 You should setup a new f

...

在开发阶段,简单的方法是使用“php artisan serve”命令。 在部署项目之后,应该按照Alexey的建议配置服务器的文档根目录。 In development phase the easy way around is using "php artisan serve" command. After you deploy the project, you should configure your server's document root as Alexey suggested.

方法名称是currentPage() ,大写currentPage() P. 您可以在文档中了解其他分页器方法 。 另外,在$author的实例为null的情况下,你回退到没有分页的Quote::all() 。 将其转换为Quote::paginate(6)以便$quotes始终是paginator的实例。 The method name is currentPage() with a capital P. You can learn about the other paginator metho

...

确实$name属性不存在。 尝试: @inject('siteInfo', 'App\Services\SiteInformation')

{{ $siteInfo->siteInfo->name }}

或者如果它是一个数组:

{{ $siteInfo->siteInfo['name'] }}

编辑 根据您的打印,尝试获取单个项目而不是集合: public function __construct() {

$this->si

...

你为什么不通过 file_get_contents($filePath)

作为变量来查看? 你的方法getDocHtml应该以这种方式返回视图: return view('viewer')->with([

'external' => file_get_contents($filePath)

]);

然后你可以通过传递$external变量做任何事情 Why don't you pass file_get_contents($filePath)

as variable to view?

...

那是因为刷新所有路线时首先由laravel处理。 我遇到了同样的问题,有两种方法: 要么将角度应用程序放在不同的域上......但是你会遇到CORS问题 或告诉laravel将任何路线路由到角应用程序,这更容易 Route::any('{path?}', function()

{

return view("index");

})->where("path", ".+");

That's because when you refresh all routes are handled by

...

1)您有Vuejs错误(添加标签plz)。 看起来你需要从vuejs容器中移出脚本标签。 2) !DOCTYPE html必须位于文档的顶部,而不是位于文档的中间。 Solved it, I made a special "app.blade.php" just for the specified view and put all my scripts in it. Not very beautiful, but It's working.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值