php laravel - 如何将控制器输出传递给 iframe 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42886570/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:36:30  来源:igfitidea点击:

php laravel - how to pass controller output to view as iframe source

phplaravel

提问by Dython

I have a controller which gives output as URL , now I want to pass the output url to view and below is the code.But when I load the view I found that iframe is not loading and the url is showing in the body of the html.

我有一个控制器,它以 URL 的形式提供输出,现在我想将输出 url 传递给视图,下面是代码。但是当我加载视图时,我发现 iframe 没有加载并且 url 显示在 html 的正文中.

inside controller this is how I am returning the output

在控制器内部,这就是我返回输出的方式

 return view('ifr',['name' => $url]);

And this is my view code

这是我的视图代码

<iframe src={{$name}}></iframe>

Could you please help me with the correct syntax

你能帮我正确的语法吗

回答by Andrius Rimkus

Instead of <iframe src={{$name}}></iframe>

代替 <iframe src={{$name}}></iframe>

Try <iframe src={!! $name !!}></iframe>

尝试 <iframe src={!! $name !!}></iframe>

More at: https://laravel.com/docs/5.4/blade/ Displaying Unescaped Data

更多信息:https: //laravel.com/docs/5.4/blade/ 显示未转义数据

回答by Rahul Chauhan

Pass the iframe src in single quotes

在单引号中传递 iframe src

Like

喜欢

$src = '"https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fhierensolanki%2Fposts%2F1264241026994313&width=500" width="500" height="608" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"';

return view('welcome',compact('src'));

And in your view file.

并在您的视图文件中。

<iframe src=<?php echo $src; ?>></iframe>

It will work.

它会起作用。