简体   繁体   English

Bootstrap外部链接模式继承

[英]Bootstrap external link modal inheritance

So I have this code that when I click View Receipt link, an external link to the receipt image will pop up in a modal. 因此,我有这段代码,当我单击“ View Receipt链接时,将以模态形式弹出指向收据图像的外部链接。 I am using twig and slim framework. 我正在使用树枝和苗条的框架。

This is my html file with the twig: 这是我的带有树枝的html文件:

{% for r in results %}
<a data-toggle="modal" href="/user/receipt/{{r.accountID}}" data-target="#myModal">View Receipt</a>
{% endfor %}

{% block script %}
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div> <!-- /.modal-content -->
    </div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
{% endblock %}

The route.php code: route.php代码:

$app->get('/user/receipt/:id', function($id) use($app) {
    $db = new db();
    $bind = array(
    ":aid" => $id
    );
    $result = $db->select("accounts", "accountID = :aid", $bind);
    $app->render('screenshot.html', array('result' => $result));
});

The screenshot.html code: screenshot.html代码:

{% for r in result %}
    <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    </div>
    <div class="modal-body">
     <img src="/assets/img/receipts/{{r.receipt}}" class="img-responsive">
    </div>
{% endfor %}

Now everything works. 现在一切正常。 The image shows up in the modal. 该图像显示在模态中。 The problem is... the first time I click a View Receipt link when the page is being loaded, all other links will contain the same image instead of the image that is based on the accountID . 问题是...加载页面时,我第一次单击View Receipt链接,所有其他链接将包含相同的图像,而不是基于accountID的图像。 All the links inherits the first link that is being clicked. 所有链接都将继承被单击的第一个链接。 What am I doing wrong? 我究竟做错了什么?

I am not sure how to do what you're currently doing - to generate modal content dynamically - but there is an alternative. 我不确定如何做您当前正在做的事情-动态生成模式内容-但是有替代方法。

You could instead wrap the modals in a for loop with their id pertaining to the the receipt id. 您可以改为将模式包装在for循环中,并将其ID与收据ID有关。 Therefore, each modal only contains their respective receipt image. 因此,每个模态仅包含其各自的收货图像。

{% for r in results %}
<a data-toggle="modal" href="/user/receipt/{{r.accountID}}" data-target="#myModal{{r.id}}">View Receipt</a>
{% endfor %}

Then your modal code would look something like this... 然后,您的模态代码将如下所示:

{% for r in results %}
<div class="modal fade" id="myModal{{r.id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
    </div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM