Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
引导模式不会加载PHP变量_Php_Html_Wordpress_Iframe_Twitter Bootstrap 3 - Fatal编程技术网

引导模式不会加载PHP变量

引导模式不会加载PHP变量,php,html,wordpress,iframe,twitter-bootstrap-3,Php,Html,Wordpress,Iframe,Twitter Bootstrap 3,我试图在引导模式中加载iframe(youtube嵌入)。如果我将iframe代码直接放入modal中,它的加载效果很好。但是当我通过变量回显iframe代码时,它将不会加载。我可以在模态外部回声出iframe,它加载得很好,只是在模态内部,iframe不会加载 这适用于案例1 <div class="modal fade" id="video-modal" tabindex="-1" role="dialog" aria-labelledby="video-modalLabel"

我试图在引导模式中加载iframe(youtube嵌入)。如果我将iframe代码直接放入modal中,它的加载效果很好。但是当我通过变量回显iframe代码时,它将不会加载。我可以在模态外部回声出iframe,它加载得很好,只是在模态内部,iframe不会加载

这适用于案例1

<div class="modal fade" id="video-modal" tabindex="-1" role="dialog" aria-labelledby="video-modalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <iframe width="1280" height="720" src="https://www.youtube.com/embed/9Gb7M7S6T7U" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
            </div>
        </div>
    </div>
</div>

这也将加载iframe案例2

<?php
    echo $video;
?>
<div class="modal fade" id="video-modal" tabindex="-1" role="dialog" aria-labelledby="video-modalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
            </div>
        </div>
    </div>
</div>

这不适用于案例3

    <div class="modal fade" id="video-modal" tabindex="-1" role="dialog" aria-labelledby="video-modalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <?php
                    echo $video;
                ?>
            </div>

        </div>
    </div>
</div>

知道为什么吗


对于上下文,这是在WordPress5、PHP7中,并且$video的值是从ACF字段调用的

经过大量研究,我找到了解决这个问题的办法。 它与PHP在呈现HTML部分之前执行有关,这会停止从PHP变量传递任何值

我知道有两种可能的解决方案,我使用了后者

本节概述了解决方案1

解决方案2是

  • 使用wp_Localize_脚本本地化iframe字符串
  • 使用jQuery从本地化数据获取字符串
  • “.html()”将iframe字符串插入模态体
  • jQuery看起来像这样

    (function ($, video_data) {
    $(document).ready(function () {
    
        var video = video_data.video_data['video'];
    
        $('#video-modal').find('.modal-body').html(video);
    
    
    });})(jQuery, video_data);
    

    经过大量研究,我找到了解决这个问题的办法。 它与PHP在呈现HTML部分之前执行有关,这会停止从PHP变量传递任何值

    我知道有两种可能的解决方案,我使用了后者

    本节概述了解决方案1

    解决方案2是

  • 使用wp_Localize_脚本本地化iframe字符串
  • 使用jQuery从本地化数据获取字符串
  • “.html()”将iframe字符串插入模态体
  • jQuery看起来像这样

    (function ($, video_data) {
    $(document).ready(function () {
    
        var video = video_data.video_data['video'];
    
        $('#video-modal').find('.modal-body').html(video);
    
    
    });})(jQuery, video_data);
    

    如果在第二种情况下从浏览器中检查元素,您是否在
    中看到任何内容?我编辑了问题,因此我假设您指的是第三种情况。但答案是否定的,没有显示任何内容,没有html或任何正确的东西,但它确实显示在(现在是第二种)情况下?在第二种情况下,它确实显示(显然是在模式外加载)只是为了解决问题,如果将echo更改为
    echo var_export($video,true),会发生什么情况对于案例2和案例3?如果在第二个案例中从浏览器检查元素,您是否在
    中看到任何内容?我编辑了问题,因此我假设您指的是第三个案例。但答案是否定的,没有显示任何内容,没有html或任何正确的东西,但它确实显示在(现在是第二种)情况下?在第二种情况下,它确实显示(显然是在模式外加载)只是为了解决问题,如果将echo更改为
    echo var_export($video,true),会发生什么情况用于案例2和案例3?