【问题标题】:click on domain name modal should open like popup点击域名模式应该像弹出窗口一样打开
【发布时间】:2019-01-09 18:22:00
【问题描述】:

在通知列表中,我使用 sql 查询来显示域名,但是当我点击每个域名时,我会打开带有详细信息的弹出窗口。

这是头文件---

 <!-- notification start -->
        <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Notification <b class="caret"></b></a>
                      <ul class="dropdown-menu short-dropdown-menu">

                         <li class=""> <a href="<?=Url::to(['domains/index']);?>">
                    <?php
                    $domains=Domains::find()
                      ->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
                      ->andWhere(['or',
                                ['status'=> 'Active'],
                                ['status'=> 'Pending Transfer']
                            ])
                      ->orderBy(['expirydate' => SORT_ASC])
                      ->all();                                                                                    
              $domainList=ArrayHelper::map($domains,'id','domainname');
              foreach($domainList as $key => $value)
                     {
                        print '<br>'. $value .'<br>';
                     }
                    ?>       
                     </a></li>                                           
                      </ul>
                    </li>
        <!-- notification ends -->

现在结果像 --- 一样打开

当点击该域名时,它必须显示如下图所示的弹出窗口-----

更新问题:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Notification <b class="caret"></b></a>
        <ul class="dropdown-menu short-dropdown-menu">
            <li class="">
                <a href="#modal-domaindetails" data-toggle="modal" onclick="getDomainDetails('2696')">

                <?php
                    $domains=Domains::find()
                            ->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
                            ->andWhere([
                                          'or',
                                          ['status'=> 'Active'],
                                          ['status'=> 'Pending Transfer']
                                      ])
                            ->orderBy(['expirydate' => SORT_ASC])
                            ->all();                        


                    $domainList=ArrayHelper::map($domains,'did','domainname');
                        foreach($domainList as $key => $value) {
                            print '<br>'. $value .'<br>';
                        }
                ?>
                </a>  
            </li>                                           
        </ul>
    </a>
</li>

现在看到这个我正在传递 id 2696 但我想根据域名获取 id 怎么可能

【问题讨论】:

  • 那么你的问题是什么? SO 不是代码编写服务。显示相关代码并说明哪一部分给您带来了麻烦。
  • 点击通知列表中打开的弹出窗口时在头文件中创建下拉列表
  • 更新了您的问题并编辑了我的答案。希望有用

标签: php mysql model-view-controller yii2


【解决方案1】:

在我看来,我有一些看法。

  1. 如果你想打开一个新的弹出模式,你必须创建一个模式弹出,像https://getbootstrap.com/docs/4.1/components/modal/

  2. 你把URL重定向到域名设置为“>”,它将被重定向到这个链接。你不能在这里弹出任何东西,除非你想在chrome中打开一个新标签或新窗口。(与打开新标签或新窗口,你可以在谷歌上搜索它)

  3. 在“li”和“a”标签中

    <li class=""> <a href="your_url"> ... your code php foreach($domainList as $key => $value) { print '<br>'. $value .'<br>'; } </a> </li>

你放了一个迭代器,它会渲染一个列表,但它们有相同的重定向到一个 URL

更新我的答案

也许我希望它会帮助你。

HTML:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Notification <b class="caret"></b></a>
        <ul class="dropdown-menu short-dropdown-menu">
            <li class="">

                <?php
                    $domains=Domains::find()
                            ->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
                            ->andWhere([
                                          'or',
                                          ['status'=> 'Active'],
                                          ['status'=> 'Pending Transfer']
                                      ])
                            ->orderBy(['expirydate' => SORT_ASC])
                            ->all();                        


                    $domainList=ArrayHelper::map($domains,'did','domainname');
                        foreach($domainList as $key => $value) {
                ?>
                <a href="javascript:;" onclick="getDomainDetails('<?= $key ?>')"><?= $value ?></a>
                <?php
                        }
                ?>

            </li>                                           
        </ul>
    </a>
</li>

添加了模态弹出窗口

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
        </div>
    </div>
</div>

JAVASCRIPT

<script>

    function getDomainDetails(domain_id) {
        $.ajax({
            url: 'domains/index',
            method: 'GET', // or 'POST'
            data: { domain_id : domain_id }
        })
        .done(function(response) {
            $('#exampleModal').find('.modal-body').html(response); // append reponse html from server
            $('#exampleModal').modal('show'); // show modal
        });
    }


</script>

【讨论】:

  • 是的,它正在呈现一个列表,但这是错误的,我想选择下拉菜单,当点击特定菜单时,它会打开一个弹出窗口。
  • 你的弹窗是什么,是不是像bootstrap的模态弹窗?
  • field($model, 'name[]')->dropDownList( ['a' => 'Item A', 'b' => 'Item B ', 'c' => '项目 C'] ); ?> ---- $model 是什么意思
  • 对不起,我不明白
  • 更新了我的答案
【解决方案2】:

使用引导模式

点击链接时,打开模态

请求服务器获取数据

再次使用 jquery 渲染数据

【讨论】:

    猜你喜欢
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多